Message373384
Strange fact, this was already fixed in 011525ee92eb1c13ad1a62d28725a840e28f8160 (which closes issue10761, nice spot Andrew) but was lost during a merge in 0d28a61d23:
$ git show 0d28a61d23
commit 0d28a61d233c02c458c8b4a25613be2f4979331e
Merge: ed3a303548 d7c9d9cdcd
$ git show 0d28a61d23:Lib/tarfile.py | grep unlink # The merge commit does no longer contains the fix
$ git show ed3a303548:Lib/tarfile.py | grep unlink # The "left" parent does not contains it neither
$ git show d7c9d9cdcd:Lib/tarfile.py | grep unlink # The "right" one does contains it.
os.unlink(targetpath)
os.unlink(targetpath)
Stranger fact, the test was not lost during the merge, and still lives today (test_extractall_symlinks).
Happen that the current test is passing because it's in part erroneous, instead of trying to create a symlink on an existing one, it creates a symlink far far away:
(Pdb) p targetpath
'/home/mdk/clones/python/cpython/@test_648875_tmp-tardir/testsymlinks/home/mdk/clones/python/cpython/@test_648875_tmp-tardir/testsymlinks/symlink'
Aditionally it passes anway because tar.errorlevel equals 1, which means the error is logged but not raised.
With the following small patch:
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -1339,10 +1339,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)
the error is raised as expected: FileExistsError: [Errno 17] File exists: '/home/mdk/clones/python/cpython/@test_649794_tmpæ-tardir/testsymlinks/source' -> '/home/mdk/clones/python/cpython/@test_649794_tmpæ-tardir/testsymlinks/symlink'
I'm opening an PR to restore this as it was intended. |
|
Date |
User |
Action |
Args |
2020-07-09 09:29:15 | mdk | set | recipients:
+ mdk, lars.gustaebel, catlee, adunand, serhiy.storchaka, andrew.garner, Jeffrey.Kintscher |
2020-07-09 09:29:15 | mdk | set | messageid: <1594286955.27.0.818296180474.issue12800@roundup.psfhosted.org> |
2020-07-09 09:29:15 | mdk | link | issue12800 messages |
2020-07-09 09:29:15 | mdk | create | |
|