bpo-12800: tarfile: Restore fix from 011525ee9 (GH-21409)
Restore fix from 011525ee92eb1c13ad1a62d28725a840e28f8160.
(cherry picked from commit 4fedd7123eaf147edd55eabbbd72e0bcc8368e47)
Co-authored-by: Julien Palard <julien@palard.fr>
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 @@
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().