mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Raise an exception when src and dst refer to the same file via a hard link or a
symbolic link (bug #851123 / patch #854853, thanks Gregory Ball).
This commit is contained in:
parent
404b06814c
commit
46f1459860
2 changed files with 32 additions and 5 deletions
|
@ -6,6 +6,7 @@ import tempfile
|
|||
import os
|
||||
import os.path
|
||||
from test import test_support
|
||||
from test.test_support import TESTFN
|
||||
|
||||
class TestShutil(unittest.TestCase):
|
||||
def test_rmtree_errors(self):
|
||||
|
@ -26,6 +27,26 @@ class TestShutil(unittest.TestCase):
|
|||
except:
|
||||
pass
|
||||
|
||||
if hasattr(os, "symlink"):
|
||||
def test_dont_copy_file_onto_link_to_itself(self):
|
||||
# bug 851123.
|
||||
os.mkdir(TESTFN)
|
||||
src = os.path.join(TESTFN,'cheese')
|
||||
dst = os.path.join(TESTFN,'shop')
|
||||
try:
|
||||
f = open(src,'w')
|
||||
f.write('cheddar')
|
||||
f.close()
|
||||
for funcname in 'link','symlink':
|
||||
getattr(os, funcname)(src, dst)
|
||||
self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
|
||||
self.assertEqual(open(src,'r').read(), 'cheddar')
|
||||
os.remove(dst)
|
||||
finally:
|
||||
try:
|
||||
shutil.rmtree(TESTFN)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def test_main():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue