diff options
author | Senthil Kumaran <orsenthil@gmail.com> | 2011-04-28 07:53:09 (GMT) |
---|---|---|
committer | Senthil Kumaran <orsenthil@gmail.com> | 2011-04-28 07:53:09 (GMT) |
commit | 8a410d319ac60347150379a92f7804bab28ac70f (patch) | |
tree | 0df2e3bb9fccaba2c4ed41de8983d2fd97063ef7 /Lib/test/test_tarfile.py | |
parent | 44aad855ddb0fed3a76c839598a9c3be31d0b7cb (diff) | |
parent | 123932f2370ba4989cd14ba01cd9721fe456c7d3 (diff) | |
download | cpython-8a410d319ac60347150379a92f7804bab28ac70f.zip cpython-8a410d319ac60347150379a92f7804bab28ac70f.tar.gz cpython-8a410d319ac60347150379a92f7804bab28ac70f.tar.bz2 |
merge from 3.1
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r-- | Lib/test/test_tarfile.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 68e094d..e3e140e 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -982,6 +982,34 @@ class WriteTest(WriteTestBase): self.assertEqual(t.name, cmp_path or path.replace(os.sep, "/")) + def test_extractall_symlinks(self): + # Test if extractall works properly when tarfile contains symlinks + tempdir = os.path.join(TEMPDIR, "testsymlinks") + temparchive = os.path.join(TEMPDIR, "testsymlinks.tar") + os.mkdir(tempdir) + try: + source_file = os.path.join(tempdir,'source') + target_file = os.path.join(tempdir,'symlink') + with open(source_file,'w') as f: + f.write('something\n') + os.symlink(source_file, target_file) + tar = tarfile.open(temparchive,'w') + tar.add(source_file) + tar.add(target_file) + tar.close() + # Let's extract it to the location which contains the symlink + tar = tarfile.open(temparchive,'r') + # this should not raise OSError: [Errno 17] File exists + try: + tar.extractall(path=tempdir) + except OSError: + self.fail("extractall failed with symlinked files") + finally: + tar.close() + finally: + os.unlink(temparchive) + shutil.rmtree(tempdir) + def test_pathnames(self): self._test_pathname("foo") self._test_pathname(os.path.join("foo", ".", "bar")) |