aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/archive_util.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-05-03 08:30:58 -0400
committerJason R. Coombs <jaraco@jaraco.com>2013-05-03 08:30:58 -0400
commitf179cf165b6c519790488127ae721204df62dd54 (patch)
tree08c83e591ec931412172f131299c3a329c23ef2d /setuptools/archive_util.py
parentbd2ad94191e790cf264062c8469996d336d1f5db (diff)
parentb03a9e293b94b338027c4983c2ac3764692dd297 (diff)
downloadexternal_python_setuptools-f179cf165b6c519790488127ae721204df62dd54.tar.gz
external_python_setuptools-f179cf165b6c519790488127ae721204df62dd54.tar.bz2
external_python_setuptools-f179cf165b6c519790488127ae721204df62dd54.zip
Merge setuptools.archive_util and setuptools.archive_util and setuptools.depends
--HG-- branch : Setuptools-Distribute merge
Diffstat (limited to 'setuptools/archive_util.py')
-rwxr-xr-xsetuptools/archive_util.py46
1 files changed, 21 insertions, 25 deletions
diff --git a/setuptools/archive_util.py b/setuptools/archive_util.py
index e22b25c0..1109f346 100755
--- a/setuptools/archive_util.py
+++ b/setuptools/archive_util.py
@@ -6,7 +6,7 @@ __all__ = [
"UnrecognizedFormat", "extraction_drivers", "unpack_directory",
]
-import zipfile, tarfile, os, shutil
+import zipfile, tarfile, os, shutil, posixpath
from pkg_resources import ensure_directory
from distutils.errors import DistutilsError
@@ -138,7 +138,7 @@ def unpack_zipfile(filename, extract_dir, progress_filter=default_filter):
name = info.filename
# don't extract absolute paths or ones with .. in them
- if name.startswith('/') or '..' in name:
+ if name.startswith('/') or '..' in name.split('/'):
continue
target = os.path.join(extract_dir, *name.split('/'))
@@ -172,43 +172,39 @@ def unpack_tarfile(filename, extract_dir, progress_filter=default_filter):
by ``tarfile.open()``). See ``unpack_archive()`` for an explanation
of the `progress_filter` argument.
"""
-
try:
tarobj = tarfile.open(filename)
except tarfile.TarError:
raise UnrecognizedFormat(
"%s is not a compressed or uncompressed tar file" % (filename,)
)
-
try:
tarobj.chown = lambda *args: None # don't do any chowning!
for member in tarobj:
name = member.name
# don't extract absolute paths or ones with .. in them
- if not name.startswith('/') and '..' not in name:
+ if not name.startswith('/') and '..' not in name.split('/'):
prelim_dst = os.path.join(extract_dir, *name.split('/'))
- final_dst = progress_filter(name, prelim_dst)
- # If progress_filter returns None, then we do not extract
- # this file
- # TODO: Do we really need to limit to just these file types?
- # tarobj.extract() will handle all files on all platforms,
- # turning file types that aren't allowed on that platform into
- # regular files.
- if final_dst and (member.isfile() or member.isdir() or
- member.islnk() or member.issym()):
- tarobj.extract(member, extract_dir)
- if final_dst != prelim_dst:
- shutil.move(prelim_dst, final_dst)
+
+ # resolve any links and to extract the link targets as normal files
+ while member is not None and (member.islnk() or member.issym()):
+ linkpath = member.linkname
+ if member.issym():
+ linkpath = posixpath.join(posixpath.dirname(member.name), linkpath)
+ linkpath = posixpath.normpath(linkpath)
+ member = tarobj._getmember(linkpath)
+
+ if member is not None and (member.isfile() or member.isdir()):
+ final_dst = progress_filter(name, prelim_dst)
+ if final_dst:
+ if final_dst.endswith(os.sep):
+ final_dst = final_dst[:-1]
+ try:
+ tarobj._extract_member(member, final_dst) # XXX Ugh
+ except tarfile.ExtractError:
+ pass # chown/chmod/mkfifo/mknode/makedev failed
return True
finally:
tarobj.close()
-
-
-
extraction_drivers = unpack_directory, unpack_zipfile, unpack_tarfile
-
-
-
-
-