dpkg: update supported compression methods
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 30 Jan 2015 14:15:38 +0000 (15:15 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 30 Jan 2015 14:15:38 +0000 (15:15 +0100)
Based on a patch by Ron Yorston <rmy@tigress.co.uk>

function                                             old     new   delta
get_header_tar_xz                                      -      60     +60
filter_accept_list_reassign                          128     188     +60
unpack_package                                       585     621     +36
init_archive_deb_control                              52      76     +24
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 3/0 up/down: 180/0)             Total: 180 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/dpkg.c
archival/dpkg_deb.c
archival/libarchive/Kbuild.src
archival/libarchive/filter_accept_list_reassign.c
archival/libarchive/get_header_tar_xz.c [new file with mode: 0644]
include/bb_archive.h

index 2893cfc2dd2fe560f0379efe59dc82c1f60ce0a1..151f0ca436b17b3b3532563c59507baa926b2b07 100644 (file)
@@ -1472,12 +1472,16 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
        tar_handle->src_fd = ar_handle->src_fd;
 
        /* We don't care about data.tar.* or debian-binary, just control.tar.* */
+       llist_add_to(&(ar_handle->accept), (char*)"control.tar");
 #if ENABLE_FEATURE_SEAMLESS_GZ
        llist_add_to(&(ar_handle->accept), (char*)"control.tar.gz");
 #endif
 #if ENABLE_FEATURE_SEAMLESS_BZ2
        llist_add_to(&(ar_handle->accept), (char*)"control.tar.bz2");
 #endif
+#if ENABLE_FEATURE_SEAMLESS_XZ
+       llist_add_to(&(ar_handle->accept), (char*)"control.tar.xz");
+#endif
 
        /* Assign the tar handle as a subarchive of the ar handle */
        ar_handle->dpkg__sub_archive = tar_handle;
@@ -1492,12 +1496,19 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
        tar_handle->src_fd = ar_handle->src_fd;
 
        /* We don't care about control.tar.* or debian-binary, just data.tar.* */
+       llist_add_to(&(ar_handle->accept), (char*)"data.tar");
 #if ENABLE_FEATURE_SEAMLESS_GZ
        llist_add_to(&(ar_handle->accept), (char*)"data.tar.gz");
 #endif
 #if ENABLE_FEATURE_SEAMLESS_BZ2
        llist_add_to(&(ar_handle->accept), (char*)"data.tar.bz2");
 #endif
+#if ENABLE_FEATURE_SEAMLESS_LZMA
+       llist_add_to(&(ar_handle->accept), (char*)"data.tar.lzma");
+#endif
+#if ENABLE_FEATURE_SEAMLESS_XZ
+       llist_add_to(&(ar_handle->accept), (char*)"data.tar.xz");
+#endif
 
        /* Assign the tar handle as a subarchive of the ar handle */
        ar_handle->dpkg__sub_archive = tar_handle;
index 13f9db991534668381d0944d24f29bdf38baabd4..0285273fec82770fe229040bdc14f8f43fc05d7a 100644 (file)
@@ -70,6 +70,8 @@ int dpkg_deb_main(int argc, char **argv)
        ar_archive->dpkg__sub_archive = tar_archive;
        ar_archive->filter = filter_accept_list_reassign;
 
+       llist_add_to(&ar_archive->accept, (char*)"data.tar");
+       llist_add_to(&control_tar_llist, (char*)"control.tar");
 #if ENABLE_FEATURE_SEAMLESS_GZ
        llist_add_to(&ar_archive->accept, (char*)"data.tar.gz");
        llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
@@ -82,6 +84,10 @@ int dpkg_deb_main(int argc, char **argv)
        llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma");
        llist_add_to(&control_tar_llist, (char*)"control.tar.lzma");
 #endif
+#if ENABLE_FEATURE_SEAMLESS_XZ
+       llist_add_to(&ar_archive->accept, (char*)"data.tar.xz");
+       llist_add_to(&control_tar_llist, (char*)"control.tar.xz");
+#endif
 
        opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
        opt = getopt32(argv, "cefXx");
index 968fdf8ab9bf1f14c13e12791d0cca02a54bae1e..7e89e9e896598374fed2c89e17a63a84e971d77f 100644 (file)
@@ -35,6 +35,7 @@ DPKG_FILES:= \
        get_header_tar_gz.o \
        get_header_tar_bz2.o \
        get_header_tar_lzma.o \
+       get_header_tar_xz.o \
 
 INSERT
 
index 3d19abe448f0ebf0203e9b50d4af3f8fc791c583..b9acfbc05428f21650a4e4b2a3c0215f0b96a096 100644 (file)
@@ -28,6 +28,10 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
                name_ptr++;
 
                /* Modify the subarchive handler based on the extension */
+               if (strcmp(name_ptr, "tar") == 0) {
+                       archive_handle->dpkg__action_data_subarchive = get_header_tar;
+                       return EXIT_SUCCESS;
+               }
                if (ENABLE_FEATURE_SEAMLESS_GZ
                 && strcmp(name_ptr, "gz") == 0
                ) {
@@ -46,6 +50,12 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
                        archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma;
                        return EXIT_SUCCESS;
                }
+               if (ENABLE_FEATURE_SEAMLESS_XZ
+                && strcmp(name_ptr, "xz") == 0
+               ) {
+                       archive_handle->dpkg__action_data_subarchive = get_header_tar_xz;
+                       return EXIT_SUCCESS;
+               }
        }
        return EXIT_FAILURE;
 }
diff --git a/archival/libarchive/get_header_tar_xz.c b/archival/libarchive/get_header_tar_xz.c
new file mode 100644 (file)
index 0000000..7bf3b3b
--- /dev/null
@@ -0,0 +1,21 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+
+#include "libbb.h"
+#include "bb_archive.h"
+
+char FAST_FUNC get_header_tar_xz(archive_handle_t *archive_handle)
+{
+       /* Can't lseek over pipes */
+       archive_handle->seek = seek_by_read;
+
+       fork_transformer_with_sig(archive_handle->src_fd, unpack_xz_stream, "unxz");
+       archive_handle->offset = 0;
+       while (get_header_tar(archive_handle) == EXIT_SUCCESS)
+               continue;
+
+       /* Can only do one file at a time */
+       return EXIT_FAILURE;
+}
index a6b166fe319d492d5e48f6ce00104ccb32b65171..5d9e24c1768183dabddef52df13c34af7a28ed29 100644 (file)
@@ -184,6 +184,7 @@ char get_header_tar(archive_handle_t *archive_handle) FAST_FUNC;
 char get_header_tar_gz(archive_handle_t *archive_handle) FAST_FUNC;
 char get_header_tar_bz2(archive_handle_t *archive_handle) FAST_FUNC;
 char get_header_tar_lzma(archive_handle_t *archive_handle) FAST_FUNC;
+char get_header_tar_xz(archive_handle_t *archive_handle) FAST_FUNC;
 
 void seek_by_jump(int fd, off_t amount) FAST_FUNC;
 void seek_by_read(int fd, off_t amount) FAST_FUNC;