[Python-checkins] python/dist/src/Lib tarfile.py,1.29,1.30
loewis@users.sourceforge.net
loewis at users.sourceforge.net
Wed Aug 24 08:07:03 CEST 2005
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7036/Lib
Modified Files:
tarfile.py
Log Message:
Patch #1262036: Make tarfile name absolute. Fixes #1257255.
Will backport to 2.4.
Index: tarfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/tarfile.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- tarfile.py 22 Jul 2005 21:49:29 -0000 1.29
+++ tarfile.py 24 Aug 2005 06:06:52 -0000 1.30
@@ -849,7 +849,7 @@
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'"
@@ -861,7 +861,7 @@
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
@@ -998,22 +998,18 @@
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"
@@ -1033,19 +1029,11 @@
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
@@ -1250,8 +1238,7 @@
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
More information about the Python-checkins
mailing list