summaryrefslogtreecommitdiffstats
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2005-08-24 06:43:09 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2005-08-24 06:43:09 (GMT)
commitfaffa15842cea1d1c3c62d5c01455c36d77b36ad (patch)
tree87c3deb0ea528a506de171a85e7e06341572226d /Lib/tarfile.py
parentbc3b06087cf1907d1dfee6e21885a9ccfbf11af3 (diff)
downloadcpython-faffa15842cea1d1c3c62d5c01455c36d77b36ad.zip
cpython-faffa15842cea1d1c3c62d5c01455c36d77b36ad.tar.gz
cpython-faffa15842cea1d1c3c62d5c01455c36d77b36ad.tar.bz2
Revert previous checkin.
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 9c25962..e4c5863 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -849,7 +849,7 @@ class TarFile(object):
can be determined, `mode' is overridden by `fileobj's mode.
`fileobj' is not closed, when TarFile is closed.
"""
- self.name = os.path.abspath(name)
+ self.name = name
if len(mode) > 1 or mode not in "raw":
raise ValueError, "mode must be 'r', 'a' or 'w'"
@@ -861,7 +861,7 @@ class TarFile(object):
self._extfileobj = False
else:
if self.name is None and hasattr(fileobj, "name"):
- self.name = os.path.abspath(fileobj.name)
+ self.name = fileobj.name
if hasattr(fileobj, "mode"):
self.mode = fileobj.mode
self._extfileobj = True
@@ -998,18 +998,22 @@ 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 = os.path.basename(pre + ext)
+ tarname = pre + ext
if fileobj is None:
fileobj = file(name, mode + "b")
+ if mode != "r":
+ name = tarname
+
try:
- t = cls.taropen(name, mode,
- gzip.GzipFile(tarname, mode, compresslevel, fileobj)
+ t = cls.taropen(tarname, mode,
+ gzip.GzipFile(name, mode, compresslevel, fileobj)
)
except IOError:
raise ReadError, "not a gzip file"
@@ -1029,11 +1033,19 @@ 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(name, mode, bz2.BZ2File(name, mode, compresslevel=compresslevel))
+ t = cls.taropen(tarname, mode, bz2.BZ2File(name, mode, compresslevel=compresslevel))
except IOError:
raise ReadError, "not a bzip2 file"
t._extfileobj = False
@@ -1238,7 +1250,8 @@ class TarFile(object):
arcname = name
# Skip if somebody tries to archive the archive...
- if self.name is not None and os.path.samefile(name, self.name):
+ if self.name is not None \
+ and os.path.abspath(name) == os.path.abspath(self.name):
self._dbg(2, "tarfile: Skipped %r" % name)
return