diff options
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/tarfile.py | 3 | ||||
-rw-r--r-- | Lib/test/test_tarfile.py | 6 |
2 files changed, 6 insertions, 3 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index e422794..1d15612 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -2237,6 +2237,9 @@ class TarFile(object): try: # For systems that support symbolic and hard links. if tarinfo.issym(): + if os.path.lexists(targetpath): + # Avoid FileExistsError on following os.symlink. + os.unlink(targetpath) os.symlink(tarinfo.linkname, targetpath) else: # See extract(). diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 7b34d53..77ad830 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -1347,10 +1347,10 @@ class WriteTest(WriteTestBase, unittest.TestCase): f.write('something\n') os.symlink(source_file, target_file) with tarfile.open(temparchive, 'w') as tar: - tar.add(source_file) - tar.add(target_file) + tar.add(source_file, arcname="source") + tar.add(target_file, arcname="symlink") # Let's extract it to the location which contains the symlink - with tarfile.open(temparchive) as tar: + with tarfile.open(temparchive, errorlevel=2) as tar: # this should not raise OSError: [Errno 17] File exists try: tar.extractall(path=tempdir) |