From 30f8ee66487a49e5ff58805a3bcaddd14bb1c428 Mon Sep 17 00:00:00 2001 From: Rene Lopez Date: Sun, 25 Oct 2009 16:50:13 -0600 Subject: [PATCH] Add support for xz compressed tars --- zeroinstall/zerostore/unpack.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/zeroinstall/zerostore/unpack.py b/zeroinstall/zerostore/unpack.py index 84b873d..642c376 100644 --- a/zeroinstall/zerostore/unpack.py +++ b/zeroinstall/zerostore/unpack.py @@ -67,7 +67,8 @@ def type_from_url(url): if url.endswith('.deb'): return 'application/x-deb' if url.endswith('.tar.bz2'): return 'application/x-bzip-compressed-tar' if url.endswith('.tar.gz'): return 'application/x-compressed-tar' - if url.endswith('.tar.lzma'): return 'application/x-lzma-compressed-tar' # XXX: No registered MIME type! + if url.endswith('.tar.lzma'): return 'application/x-lzma-compressed-tar' + if url.endswith('.tar.xz'): return 'application/x-xz-compressed-tar' if url.endswith('.tgz'): return 'application/x-compressed-tar' if url.endswith('.tar'): return 'application/x-tar' if url.endswith('.zip'): return 'application/zip' @@ -103,6 +104,11 @@ def check_type_ok(mime_type): "I need to extract it. Install the package containing it first.")) elif mime_type == 'application/x-lzma-compressed-tar': pass # We can get it through Zero Install + elif mime_type == 'application/x-xz-compressed-tar': + if not find_in_path('unxz'): + raise SafeException(_("This package looks like a xz-compressed package, but you don't have the 'unxz' command " + "I need to extract it. Install the package containing it (it's probably called 'xz-utils') " + "first.")) elif mime_type in ('application/x-compressed-tar', 'application/x-tar'): pass else: @@ -190,6 +196,8 @@ def unpack_archive(url, data, destdir, extract = None, type = None, start_offset extract_tar(data, destdir, extract, None, start_offset) elif type == 'application/x-lzma-compressed-tar': extract_tar(data, destdir, extract, 'lzma', start_offset) + elif type == 'application/x-xz-compressed-tar': + extract_tar(data, destdir, extract, 'xz', start_offset) elif type == 'application/x-compressed-tar': extract_tar(data, destdir, extract, 'gzip', start_offset) elif type == 'application/vnd.ms-cab-compressed': @@ -322,7 +330,7 @@ def extract_tar(stream, destdir, extract, decompress, start_offset = 0): if not re.match('^[a-zA-Z0-9][- _a-zA-Z0-9.]*$', extract): raise SafeException(_('Illegal character in extract attribute')) - assert decompress in [None, 'bzip2', 'gzip', 'lzma'] + assert decompress in [None, 'bzip2', 'gzip', 'lzma', 'xz'] if _gnu_tar(): ext_cmd = ['tar'] @@ -336,6 +344,8 @@ def extract_tar(stream, destdir, extract, decompress, start_offset = 0): if not unlzma: unlzma = os.path.abspath(os.path.join(os.path.dirname(__file__), '_unlzma')) ext_cmd.append('--use-compress-program=' + unlzma) + elif decompress == 'xz': + ext_cmd.append('--use-compress-program=unxz') if recent_gnu_tar(): ext_cmd.extend(('-x', '--no-same-owner', '--no-same-permissions')) @@ -348,7 +358,7 @@ def extract_tar(stream, destdir, extract, decompress, start_offset = 0): _extract(stream, destdir, ext_cmd, start_offset) else: # Since we don't have GNU tar, use python's tarfile module. This will probably - # be a lot slower and we do not support lzma; however, it is portable. + # be a lot slower and we do not support lzma and xz; however, it is portable. if decompress is None: rmode = 'r|' elif decompress == 'bzip2': -- 2.11.4.GIT