Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a410d3

Browse files
committed
merge from 3.1
2 parents 44aad85 + 123932f commit 8a410d3

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lib/test/test_tarfile.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,34 @@ def _test_pathname(self, path, cmp_path=None, dir=False):
982982

983983
self.assertEqual(t.name, cmp_path or path.replace(os.sep, "/"))
984984

985+
def test_extractall_symlinks(self):
986+
# Test if extractall works properly when tarfile contains symlinks
987+
tempdir = os.path.join(TEMPDIR, "testsymlinks")
988+
temparchive = os.path.join(TEMPDIR, "testsymlinks.tar")
989+
os.mkdir(tempdir)
990+
try:
991+
source_file = os.path.join(tempdir,'source')
992+
target_file = os.path.join(tempdir,'symlink')
993+
with open(source_file,'w') as f:
994+
f.write('something\n')
995+
os.symlink(source_file, target_file)
996+
tar = tarfile.open(temparchive,'w')
997+
tar.add(source_file)
998+
tar.add(target_file)
999+
tar.close()
1000+
# Let's extract it to the location which contains the symlink
1001+
tar = tarfile.open(temparchive,'r')
1002+
# this should not raise OSError: [Errno 17] File exists
1003+
try:
1004+
tar.extractall(path=tempdir)
1005+
except OSError:
1006+
self.fail("extractall failed with symlinked files")
1007+
finally:
1008+
tar.close()
1009+
finally:
1010+
os.unlink(temparchive)
1011+
shutil.rmtree(tempdir)
1012+
9851013
def test_pathnames(self):
9861014
self._test_pathname("foo")
9871015
self._test_pathname(os.path.join("foo", ".", "bar"))

0 commit comments

Comments
 (0)