[3.13] gh-75989: TarFile.extractall and TarFile.extract now overwrite symlinks when extracting hardlinks (GH-137316) (GH-139771)

(cherry picked from commit 481d5b5455)

Co-authored-by: Alexander Urieles <aeurielesn@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2025-10-09 12:54:14 +02:00 committed by GitHub
parent 69a34938f8
commit abe6f529ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 57 additions and 0 deletions

View file

@ -2660,6 +2660,9 @@ def makelink_with_filter(self, tarinfo, targetpath,
return
else:
if os.path.exists(tarinfo._link_target):
if os.path.lexists(targetpath):
# Avoid FileExistsError on following os.link.
os.unlink(targetpath)
os.link(tarinfo._link_target, targetpath)
return
except symlink_exception: