diff options
author | Charles-François Natali <neologix@free.fr> | 2011-07-29 19:00:38 +0200 |
---|---|---|
committer | Charles-François Natali <neologix@free.fr> | 2011-07-29 19:00:38 +0200 |
commit | e12c0b1767309ec1fe727e91f8d4c0cfae4a88a8 (patch) | |
tree | d9d106ff50730f60120133eb3a43158129228245 /Lib/test | |
parent | 516c51c14c06913ac832b0f50989e83c6f3bb730 (diff) | |
parent | def35435ee4001f8aedac01b559bb0dc2d0aab00 (diff) | |
download | cpython-git-e12c0b1767309ec1fe727e91f8d4c0cfae4a88a8.tar.gz |
Issue #12464: tempfile.TemporaryDirectory.cleanup() should not follow symlinks:
fix it. Patch by Petri Lehtinen.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_tempfile.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 2d298857b2..f7f5bdadbd 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -964,6 +964,27 @@ class test_TemporaryDirectory(TC): finally: os.rmdir(dir) + @support.skip_unless_symlink + def test_cleanup_with_symlink_to_a_directory(self): + # cleanup() should not follow symlinks to directories (issue #12464) + d1 = self.do_create() + d2 = self.do_create() + + # Symlink d1/foo -> d2 + os.symlink(d2.name, os.path.join(d1.name, "foo")) + + # This call to cleanup() should not follow the "foo" symlink + d1.cleanup() + + self.assertFalse(os.path.exists(d1.name), + "TemporaryDirectory %s exists after cleanup" % d1.name) + self.assertTrue(os.path.exists(d2.name), + "Directory pointed to by a symlink was deleted") + self.assertEqual(os.listdir(d2.name), ['test.txt'], + "Contents of the directory pointed to by a symlink " + "were deleted") + d2.cleanup() + @support.cpython_only def test_del_on_collection(self): # A TemporaryDirectory is deleted when garbage collected |