[issue10761] tarfile.extractall fails to overwrite symlinks

Scott Leerssen report at bugs.python.org
Fri May 13 18:57:08 CEST 2011


Scott Leerssen <sleerssen at gmail.com> added the comment:

here is a diff of a better fix based on the previous patch:


Index: tarfile.py
===================================================================
--- tarfile.py  (revision 49758)
+++ tarfile.py  (working copy)
@@ -2239,12 +2239,14 @@
         if hasattr(os, "symlink") and hasattr(os, "link"):
             # For systems that support symbolic and hard links.
             if tarinfo.issym():
-                if os.path.exists(targetpath):
+                if os.path.lexists(targetpath):
                     os.unlink(targetpath)
                 os.symlink(tarinfo.linkname, targetpath)
             else:
                 # See extract().
                 if os.path.exists(tarinfo._link_target):
+                    if os.path.lexists(targetpath):
+                        os.unlink(targetpath)
                     os.link(tarinfo._link_target, targetpath)
                 else:
                     self._extract_member(self._find_link_target(tarinfo), targetpath)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10761>
_______________________________________


More information about the Python-bugs-list mailing list