summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2011-04-28 07:38:12 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2011-04-28 07:38:12 (GMT)
commit123932f2370ba4989cd14ba01cd9721fe456c7d3 (patch)
treea8b725c4ecf004204bd45f8856da649c566d3078 /Lib/test/test_tarfile.py
parentb185a04aa10209df7c5fa329696e3c33c38eba7a (diff)
downloadcpython-123932f2370ba4989cd14ba01cd9721fe456c7d3.zip
cpython-123932f2370ba4989cd14ba01cd9721fe456c7d3.tar.gz
cpython-123932f2370ba4989cd14ba01cd9721fe456c7d3.tar.bz2
Add tests for tarfile extractall feature when with symlinks
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r--Lib/test/test_tarfile.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 124f0e9..487f28f 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -678,6 +678,33 @@ class WriteTest(WriteTestBase):
finally:
shutil.rmtree(tempdir)
+ 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)
class StreamWriteTest(WriteTestBase):