Commit c4362bb8 authored by Julien Muchembled's avatar Julien Muchembled

default: add support for xz/lz archives to 'self.extract'

parent 1046b48f
Pipeline #19076 passed with stage
in 0 seconds
......@@ -36,7 +36,7 @@ import tempfile
from setuptools import archive_util
import zc.buildout
from .. import is_true, rmtree, EnvironMixin, Shared
from ..downloadunpacked import extraction_drivers, patched_extraction_drivers
from ..downloadunpacked import unpack_archive
def readElfAsDict(f):
"""Reads ELF information from file"""
......@@ -155,11 +155,7 @@ class Script(EnvironMixin):
extract_dir = tempfile.mkdtemp(self.name)
self.cleanup_list.append(extract_dir)
self.logger.debug('Created working directory: %s', extract_dir)
try:
archive_util.extraction_drivers = patched_extraction_drivers
archive_util.unpack_archive(path, extract_dir)
finally:
archive_util.extraction_drivers = extraction_drivers
unpack_archive(self, path, extract_dir)
return extract_dir
def pipeCommand(self, command_list_list, *args, **kwargs):
......
......@@ -66,25 +66,10 @@ class Recipe(EnvironMixin):
hash_name=True)(self._url, self.options.get('md5sum') or None,
**({'alternate_url': alternate} if alternate else {}))
try:
archive_util.extraction_drivers = patched_extraction_drivers
# ad-hoc support for .xz and .lz archive
with open(path, 'rb') as f:
hdr = f.read(6)
for magic, cmd in ((b'\xfd7zXZ\x00', ('xzcat',)),
(b'LZIP', ('lunzip', '-c'))):
if hdr.startswith(magic):
with tempfile.NamedTemporaryFile() as uncompressed_archive:
subprocess.check_call(cmd + (path,),
stdout=uncompressed_archive, env=self.environ)
archive_util.unpack_archive(
uncompressed_archive.name, location)
break
else:
archive_util.unpack_archive(path, location)
unpack_archive(self, path, location)
finally:
if is_temp:
os.unlink(path)
archive_util.extraction_drivers = extraction_drivers
strip = self._strip
if strip is None:
......@@ -108,9 +93,11 @@ class Recipe(EnvironMixin):
def update(self):
pass
# Monkey patch to keep symlinks in tarfile
def unpack_tarfile_patched(filename, extract_dir,
progress_filter=archive_util.default_filter):
def unpack_archive(recipe, *args):
# Monkey patch to keep symlinks in tarfile
def unpack_tarfile_patched(filename, extract_dir,
progress_filter=archive_util.default_filter):
"""Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`
Raises ``UnrecognizedFormat`` if `filename` is not a tarfile (as determined
......@@ -120,6 +107,18 @@ def unpack_tarfile_patched(filename, extract_dir,
try:
tarobj = tarfile.open(filename)
except tarfile.TarError:
# ad-hoc support for .xz and .lz archive
with open(filename, 'rb') as f:
hdr = f.read(6)
for magic, cmd in ((b'\xfd7zXZ\x00', ('xzcat',)),
(b'LZIP', ('lunzip', '-c'))):
if hdr.startswith(magic):
with tempfile.NamedTemporaryFile() as uncompressed_archive:
subprocess.check_call(cmd + (filename,),
stdout=uncompressed_archive, env=recipe.environ)
archive_util.unpack_archive(
uncompressed_archive.name, extract_dir, progress_filter)
return True
raise archive_util.UnrecognizedFormat(
"%s is not a compressed or uncompressed tar file" % (filename,)
)
......@@ -148,7 +147,5 @@ def unpack_tarfile_patched(filename, extract_dir,
pass
return True
extraction_drivers = archive_util.extraction_drivers
patched_extraction_drivers = extraction_drivers[:2] + (
unpack_tarfile_patched,
)
return archive_util.unpack_archive(*args,
drivers = archive_util.extraction_drivers[:2] + (unpack_tarfile_patched,))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment