This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=eded8c747c297baf1b8142d58afe0a6a2caf058d

commit eded8c747c297baf1b8142d58afe0a6a2caf058d (HEAD -> main)
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Mon Jul 19 03:45:06 2021 +0200

    libdpkg: Pass struct compress_params to decompressors
    
    This way we will be able to pass other parameters controlling the
    decompression, which we will use with the upcoming multithreaded
    xz decompressor support.
---
 lib/dpkg/compress.c | 36 ++++++++++++++++++++++++------------
 lib/dpkg/compress.h |  2 +-
 src/deb/extract.c   | 18 ++++++++++--------
 3 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/lib/dpkg/compress.c b/lib/dpkg/compress.c
index 5a391b4e8..325593041 100644
--- a/lib/dpkg/compress.c
+++ b/lib/dpkg/compress.c
@@ -98,7 +98,8 @@ struct compressor {
        void (*fixup_params)(struct compress_params *params);
        void (*compress)(struct compress_params *params,
                         int fd_in, int fd_out, const char *desc);
-       void (*decompress)(int fd_in, int fd_out, const char *desc);
+       void (*decompress)(struct compress_params *params,
+                          int fd_in, int fd_out, const char *desc);
 };
 
 /*
@@ -111,7 +112,8 @@ fixup_none_params(struct compress_params *params)
 }
 
 static void
-decompress_none(int fd_in, int fd_out, const char *desc)
+decompress_none(struct compress_params *params, int fd_in, int fd_out,
+                const char *desc)
 {
        struct dpkg_error err;
 
@@ -154,7 +156,8 @@ fixup_gzip_params(struct compress_params *params)
 
 #if defined(WITH_LIBZ_NG) || defined(WITH_LIBZ)
 static void
-decompress_gzip(int fd_in, int fd_out, const char *desc)
+decompress_gzip(struct compress_params *params, int fd_in, int fd_out,
+                const char *desc)
 {
        char *buffer;
        size_t bufsize = DPKG_BUFFER_SIZE;
@@ -269,7 +272,8 @@ compress_gzip(struct compress_params *params, int fd_in, 
int fd_out,
 static const char *env_gzip[] = { "GZIP", NULL };
 
 static void
-decompress_gzip(int fd_in, int fd_out, const char *desc)
+decompress_gzip(struct compress_params *params, int fd_in, int fd_out,
+                const char *desc)
 {
        fd_fd_filter(fd_in, fd_out, desc, env_gzip, GZIP, "-dc", NULL);
 }
@@ -310,7 +314,8 @@ fixup_bzip2_params(struct compress_params *params)
 
 #ifdef WITH_LIBBZ2
 static void
-decompress_bzip2(int fd_in, int fd_out, const char *desc)
+decompress_bzip2(struct compress_params *params, int fd_in, int fd_out,
+                 const char *desc)
 {
        char *buffer;
        size_t bufsize = DPKG_BUFFER_SIZE;
@@ -409,7 +414,8 @@ compress_bzip2(struct compress_params *params, int fd_in, 
int fd_out,
 static const char *env_bzip2[] = { "BZIP", "BZIP2", NULL };
 
 static void
-decompress_bzip2(int fd_in, int fd_out, const char *desc)
+decompress_bzip2(struct compress_params *params, int fd_in, int fd_out,
+                 const char *desc)
 {
        fd_fd_filter(fd_in, fd_out, desc, env_bzip2, BZIP2, "-dc", NULL);
 }
@@ -752,7 +758,8 @@ filter_lzma_done(struct io_lzma *io, lzma_stream *s)
 }
 
 static void
-decompress_xz(int fd_in, int fd_out, const char *desc)
+decompress_xz(struct compress_params *params, int fd_in, int fd_out,
+              const char *desc)
 {
        struct io_lzma io;
 
@@ -760,6 +767,7 @@ decompress_xz(int fd_in, int fd_out, const char *desc)
        io.code = filter_lzma_code;
        io.done = filter_lzma_done;
        io.desc = desc;
+       io.params = params;
 
        filter_lzma(&io, fd_in, fd_out);
 }
@@ -782,7 +790,8 @@ compress_xz(struct compress_params *params, int fd_in, int 
fd_out,
 static const char *env_xz[] = { "XZ_DEFAULTS", "XZ_OPT", NULL };
 
 static void
-decompress_xz(int fd_in, int fd_out, const char *desc)
+decompress_xz(struct compress_params *params, int fd_in, int fd_out,
+              const char *desc)
 {
        fd_fd_filter(fd_in, fd_out, desc, env_xz, XZ, "-dc", NULL);
 }
@@ -852,7 +861,8 @@ filter_lzma_init(struct io_lzma *io, lzma_stream *s)
 }
 
 static void
-decompress_lzma(int fd_in, int fd_out, const char *desc)
+decompress_lzma(struct compress_params *params, int fd_in, int fd_out,
+                const char *desc)
 {
        struct io_lzma io;
 
@@ -860,6 +870,7 @@ decompress_lzma(int fd_in, int fd_out, const char *desc)
        io.code = filter_lzma_code;
        io.done = filter_lzma_done;
        io.desc = desc;
+       io.params = params;
 
        filter_lzma(&io, fd_in, fd_out);
 }
@@ -880,7 +891,8 @@ compress_lzma(struct compress_params *params, int fd_in, 
int fd_out,
 }
 #else
 static void
-decompress_lzma(int fd_in, int fd_out, const char *desc)
+decompress_lzma(struct compress_params *params, int fd_in, int fd_out,
+                const char *desc)
 {
        fd_fd_filter(fd_in, fd_out, desc, env_xz, XZ, "-dc", "--format=lzma", 
NULL);
 }
@@ -1016,7 +1028,7 @@ compressor_check_params(struct compress_params *params, 
struct dpkg_error *err)
 }
 
 void
-decompress_filter(enum compressor_type type, int fd_in, int fd_out,
+decompress_filter(struct compress_params *params, int fd_in, int fd_out,
                   const char *desc_fmt, ...)
 {
        va_list args;
@@ -1026,7 +1038,7 @@ decompress_filter(enum compressor_type type, int fd_in, 
int fd_out,
        varbuf_vprintf(&desc, desc_fmt, args);
        va_end(args);
 
-       compressor(type)->decompress(fd_in, fd_out, desc.buf);
+       compressor(params->type)->decompress(params, fd_in, fd_out, desc.buf);
 
        varbuf_destroy(&desc);
 }
diff --git a/lib/dpkg/compress.h b/lib/dpkg/compress.h
index 08aaf2516..e075e525a 100644
--- a/lib/dpkg/compress.h
+++ b/lib/dpkg/compress.h
@@ -71,7 +71,7 @@ enum compressor_strategy compressor_get_strategy(const char 
*name);
 bool compressor_check_params(struct compress_params *params,
                              struct dpkg_error *err);
 
-void decompress_filter(enum compressor_type type, int fd_in, int fd_out,
+void decompress_filter(struct compress_params *params, int fd_in, int fd_out,
                        const char *desc, ...)
                        DPKG_ATTR_PRINTF(4);
 void compress_filter(struct compress_params *params, int fd_in, int fd_out,
diff --git a/src/deb/extract.c b/src/deb/extract.c
index 4d0219840..a1b2dc0bf 100644
--- a/src/deb/extract.c
+++ b/src/deb/extract.c
@@ -118,7 +118,9 @@ extracthalf(const char *debar, const char *dir,
   char nlc;
   int adminmember = -1;
   bool header_done;
-  enum compressor_type decompressor = COMPRESSOR_TYPE_GZIP;
+  struct compress_params decompress_params = {
+    .type = COMPRESSOR_TYPE_GZIP,
+  };
 
   ar = dpkg_ar_open(debar);
 
@@ -176,10 +178,10 @@ extracthalf(const char *debar, const char *dir,
           const char *extension = arh.ar_name + strlen(ADMINMEMBER);
 
          adminmember = 1;
-          decompressor = compressor_find_by_extension(extension);
-          if (decompressor != COMPRESSOR_TYPE_NONE &&
-              decompressor != COMPRESSOR_TYPE_GZIP &&
-              decompressor != COMPRESSOR_TYPE_XZ)
+          decompress_params.type = compressor_find_by_extension(extension);
+          if (decompress_params.type != COMPRESSOR_TYPE_NONE &&
+              decompress_params.type != COMPRESSOR_TYPE_GZIP &&
+              decompress_params.type != COMPRESSOR_TYPE_XZ)
             ohshit(_("archive '%s' uses unknown compression for member '%.*s', 
"
                      "giving up"),
                    debar, (int)sizeof(arh.ar_name), arh.ar_name);
@@ -193,8 +195,8 @@ extracthalf(const char *debar, const char *dir,
            const char *extension = arh.ar_name + strlen(DATAMEMBER);
 
            adminmember= 0;
-           decompressor = compressor_find_by_extension(extension);
-            if (decompressor == COMPRESSOR_TYPE_UNKNOWN)
+            decompress_params.type = compressor_find_by_extension(extension);
+            if (decompress_params.type == COMPRESSOR_TYPE_UNKNOWN)
               ohshit(_("archive '%s' uses unknown compression for member 
'%.*s', "
                        "giving up"),
                      debar, (int)sizeof(arh.ar_name), arh.ar_name);
@@ -296,7 +298,7 @@ extracthalf(const char *debar, const char *dir,
   if (!c2) {
     if (taroption)
       close(p2[0]);
-    decompress_filter(decompressor, p1[0], p2_out,
+    decompress_filter(&decompress_params, p1[0], p2_out,
                       _("decompressing archive '%s' (size=%jd) member '%s'"),
                       ar->name, (intmax_t)ar->size,
                       admininfo ? ADMINMEMBER : DATAMEMBER);

-- 
Dpkg.Org's dpkg

Reply via email to