summaryrefslogtreecommitdiffstats
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2009-08-28 19:59:59 (GMT)
committerLars Gustäbel <lars@gustaebel.de>2009-08-28 19:59:59 (GMT)
commitbfdfdda1067ae32f72040a0b6aefa5807e41da51 (patch)
tree3a38857be9246ebb0b23a3560217a376990f4761 /Lib/tarfile.py
parentd314e1b9291544640a9a85542b335d692a9576b6 (diff)
downloadcpython-bfdfdda1067ae32f72040a0b6aefa5807e41da51.zip
cpython-bfdfdda1067ae32f72040a0b6aefa5807e41da51.tar.gz
cpython-bfdfdda1067ae32f72040a0b6aefa5807e41da51.tar.bz2
Merged revisions 74571 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r74571 | lars.gustaebel | 2009-08-28 21:23:44 +0200 (Fri, 28 Aug 2009) | 7 lines Issue #6054: Do not normalize stored pathnames. No longer use tarfile.normpath() on pathnames. Store pathnames unchanged, i.e. do not remove "./", "../" and "//" occurrences. However, still convert absolute to relative paths. ........
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py41
1 files changed, 12 insertions, 29 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 3a3d2c9..ebaffd9 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -309,11 +309,6 @@ def filemode(mode):
perm.append("-")
return "".join(perm)
-if os.sep != "/":
- normpath = lambda path: os.path.normpath(path).replace(os.sep, "/")
-else:
- normpath = os.path.normpath
-
class TarError(Exception):
"""Base exception."""
pass
@@ -955,7 +950,7 @@ class TarInfo(object):
"""Return the TarInfo's attributes as a dictionary.
"""
info = {
- "name": normpath(self.name),
+ "name": self.name,
"mode": self.mode & 0o7777,
"uid": self.uid,
"gid": self.gid,
@@ -963,7 +958,7 @@ class TarInfo(object):
"mtime": self.mtime,
"chksum": self.chksum,
"type": self.type,
- "linkname": normpath(self.linkname) if self.linkname else "",
+ "linkname": self.linkname,
"uname": self.uname,
"gname": self.gname,
"devmajor": self.devmajor,
@@ -1795,10 +1790,9 @@ class TarFile(object):
# Absolute paths are turned to relative paths.
if arcname is None:
arcname = name
- arcname = normpath(arcname)
drv, arcname = os.path.splitdrive(arcname)
- while arcname[0:1] == "/":
- arcname = arcname[1:]
+ arcname = arcname.replace(os.sep, "/")
+ arcname = arcname.lstrip("/")
# Now, fill the TarInfo object with
# information specific for the file.
@@ -1927,16 +1921,6 @@ class TarFile(object):
self._dbg(2, "tarfile: Skipped %r" % name)
return
- # Special case: The user wants to add the current
- # working directory.
- if name == ".":
- if recursive:
- if arcname == ".":
- arcname = ""
- for f in os.listdir(name):
- self.add(f, os.path.join(arcname, f), recursive, exclude)
- return
-
self._dbg(1, name)
# Create a TarInfo object from the file.
@@ -2103,9 +2087,8 @@ class TarFile(object):
# Fetch the TarInfo object for the given name
# and build the destination pathname, replacing
# forward slashes to platform specific separators.
- if targetpath[-1:] == "/":
- targetpath = targetpath[:-1]
- targetpath = os.path.normpath(targetpath)
+ targetpath = targetpath.rstrip("/")
+ targetpath = targetpath.replace("/", os.sep)
# Create all upper directories.
upperdirs = os.path.dirname(targetpath)
@@ -2200,23 +2183,23 @@ class TarFile(object):
(platform limitation), we try to make a copy of the referenced file
instead of a link.
"""
- linkpath = tarinfo.linkname
try:
if tarinfo.issym():
- os.symlink(linkpath, targetpath)
+ os.symlink(tarinfo.linkname, targetpath)
else:
# See extract().
os.link(tarinfo._link_target, targetpath)
except AttributeError:
if tarinfo.issym():
- linkpath = os.path.join(os.path.dirname(tarinfo.name),
- linkpath)
- linkpath = normpath(linkpath)
+ linkpath = os.path.dirname(tarinfo.name) + "/" + \
+ tarinfo.linkname
+ else:
+ linkpath = tarinfo.linkname
try:
self._extract_member(self.getmember(linkpath), targetpath)
except (EnvironmentError, KeyError) as e:
- linkpath = os.path.normpath(linkpath)
+ linkpath = linkpath.replace("/", os.sep)
try:
shutil.copy2(linkpath, targetpath)
except EnvironmentError as e: