]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Patch #1262036: Make tarfile name absolute. Fixes #1257255.
authorMartin v. Löwis <martin@v.loewis.de>
Wed, 24 Aug 2005 06:07:17 +0000 (06:07 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Wed, 24 Aug 2005 06:07:17 +0000 (06:07 +0000)
Lib/tarfile.py
Misc/NEWS

index 366a244ab5a96d30cad35eb1fe30387ac1814760..363bbee8addf9e0f589395e45ef8f99e2fd6f131 100644 (file)
@@ -800,7 +800,7 @@ class TarFile(object):
            can be determined, `mode' is overridden by `fileobj's mode.
            `fileobj' is not closed, when TarFile is closed.
         """
-        self.name = name
+        self.name = os.path.abspath(name)
 
         if len(mode) > 1 or mode not in "raw":
             raise ValueError, "mode must be 'r', 'a' or 'w'"
@@ -812,7 +812,7 @@ class TarFile(object):
             self._extfileobj = False
         else:
             if self.name is None and hasattr(fileobj, "name"):
-                self.name = fileobj.name
+                self.name = os.path.abspath(fileobj.name)
             if hasattr(fileobj, "mode"):
                 self.mode = fileobj.mode
             self._extfileobj = True
@@ -948,22 +948,18 @@ class TarFile(object):
             raise CompressionError, "gzip module is not available"
 
         pre, ext = os.path.splitext(name)
-        pre = os.path.basename(pre)
         if ext == ".tgz":
             ext = ".tar"
         if ext == ".gz":
             ext = ""
-        tarname = pre + ext
+        tarname = os.path.basename(pre + ext)
 
         if fileobj is None:
             fileobj = file(name, mode + "b")
 
-        if mode != "r":
-            name = tarname
-
         try:
-            t = cls.taropen(tarname, mode,
-                gzip.GzipFile(name, mode, compresslevel, fileobj)
+            t = cls.taropen(name, mode,
+                gzip.GzipFile(tarname, mode, compresslevel, fileobj)
             )
         except IOError:
             raise ReadError, "not a gzip file"
@@ -984,19 +980,11 @@ class TarFile(object):
         except ImportError:
             raise CompressionError, "bz2 module is not available"
 
-        pre, ext = os.path.splitext(name)
-        pre = os.path.basename(pre)
-        if ext == ".tbz2":
-            ext = ".tar"
-        if ext == ".bz2":
-            ext = ""
-        tarname = pre + ext
-
         if fileobj is not None:
             raise ValueError, "no support for external file objects"
 
         try:
-            t = cls.taropen(tarname, mode, bz2.BZ2File(name, mode, compresslevel=compresslevel))
+            t = cls.taropen(name, mode, bz2.BZ2File(name, mode, compresslevel=compresslevel))
         except IOError:
             raise ReadError, "not a bzip2 file"
         t._extfileobj = False
@@ -1203,8 +1191,7 @@ class TarFile(object):
             arcname = name
 
         # Skip if somebody tries to archive the archive...
-        if self.name is not None \
-            and os.path.abspath(name) == os.path.abspath(self.name):
+        if self.name is not None and os.path.samefile(name, self.name):
             self._dbg(2, "tarfile: Skipped %r" % name)
             return
 
index 808d58bb351f13ef94a513f3122c5bbd864d8622..c8149ddbee7854ff27a52d252cefa7fc616e6fea 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -63,6 +63,8 @@ Extension Modules
 Library
 -------
 
+- Patch #1262036: Make tarfile name absolute. Fixes #1257255.
+
 - Bug #1266283: "lexists" is now in os.path.__all__.
 
 - The sets module can now properly compute s-=s and s^=s as an empty set.