diff options
author | Johannes Gijsbers <jlg@dds.nl> | 2004-08-14 13:30:02 (GMT) |
---|---|---|
committer | Johannes Gijsbers <jlg@dds.nl> | 2004-08-14 13:30:02 (GMT) |
commit | 46f1459860280d9f57d92f1fb389f657e0b2724b (patch) | |
tree | f94de8d643c7a7171d664e73ca75999251ee8223 /Lib/test | |
parent | 404b06814c1e6d527b6e659a907ca1b15a6eaa28 (diff) | |
download | cpython-46f1459860280d9f57d92f1fb389f657e0b2724b.zip cpython-46f1459860280d9f57d92f1fb389f657e0b2724b.tar.gz cpython-46f1459860280d9f57d92f1fb389f657e0b2724b.tar.bz2 |
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).
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_shutil.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index bcae72f..083dbda 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -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(): |