Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6812871

Browse files
author
Johannes Gijsbers
committed
Unwrap too-smart loop: we can't use src for both hard and symbolic links.
1 parent 46f1459 commit 6812871

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

Lib/test/test_shutil.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,25 @@ def test_dont_move_dir_in_itself(self):
3131
def test_dont_copy_file_onto_link_to_itself(self):
3232
# bug 851123.
3333
os.mkdir(TESTFN)
34-
src = os.path.join(TESTFN,'cheese')
35-
dst = os.path.join(TESTFN,'shop')
34+
src = os.path.join(TESTFN, 'cheese')
35+
dst = os.path.join(TESTFN, 'shop')
3636
try:
37-
f = open(src,'w')
37+
f = open(src, 'w')
3838
f.write('cheddar')
3939
f.close()
40-
for funcname in 'link','symlink':
41-
getattr(os, funcname)(src, dst)
42-
self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
43-
self.assertEqual(open(src,'r').read(), 'cheddar')
44-
os.remove(dst)
40+
41+
os.link(src, dst)
42+
self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
43+
self.assertEqual(open(src,'r').read(), 'cheddar')
44+
os.remove(dst)
45+
46+
# Using `src` here would mean we end up with a symlink pointing
47+
# to TESTFN/TESTFN/cheese, while it should point at
48+
# TESTFN/cheese.
49+
os.symlink('cheese', dst)
50+
self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
51+
self.assertEqual(open(src,'r').read(), 'cheddar')
52+
os.remove(dst)
4553
finally:
4654
try:
4755
shutil.rmtree(TESTFN)

0 commit comments

Comments
 (0)