Note that Dpkg::Compression still assumes a usable “lzma” command.
---
This is very rough, including some repetitive code.  It’s not
enough to accomplish what I would like, since the perl module
Dpkg::Compression should also be changed.  I’m sending it out
now to get feedback --- e.g. if my approach is wrong in some
way, it would be nice to learn that early. :)
Thanks,
Jonathan

 lib/dpkg/compression.c |   46 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/lib/dpkg/compression.c b/lib/dpkg/compression.c
index 3886ee1..90dd374 100644
--- a/lib/dpkg/compression.c
+++ b/lib/dpkg/compression.c
@@ -17,10 +17,12 @@
 
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
+#include <dpkg/path.h>
 
 static void
 fd_fd_filter(int fd_in, int fd_out,
-            const char *file, const char *cmd, const char *args,
+            const char *file, const char *cmd,
+            const char *arg1, const char *arg2,
             const char *desc)
 {
   if (fd_in != 0) {
@@ -31,8 +33,12 @@ fd_fd_filter(int fd_in, int fd_out,
     m_dup2(fd_out, 1);
     close(fd_out);
   }
-  execlp(file, cmd, args, NULL);
-  ohshite(_("%s: failed to exec '%s %s'"), desc, cmd, args);
+  if (arg2) {
+    execlp(file, cmd, arg1, arg2, NULL);
+    ohshite(_("%s: failed to exec '%s %s %s'"), desc, cmd, arg1, arg2);
+  }
+  execlp(file, cmd, arg1, NULL);
+  ohshite(_("%s: failed to exec '%s %s'"), desc, cmd, arg1);
 }
 
 void decompress_cat(enum compress_type type, int fd_in, int fd_out, char 
*desc, ...) {
@@ -65,7 +71,7 @@ void decompress_cat(enum compress_type type, int fd_in, int 
fd_out, char *desc,
       }
       exit(0);
 #else
-      fd_fd_filter(fd_in, fd_out, GZIP, "gzip", "-dc", v.buf);
+      fd_fd_filter(fd_in, fd_out, GZIP, "gzip", "-dc", NULL, v.buf);
 #endif
     case compress_type_bzip2:
 #ifdef WITH_BZ2
@@ -88,10 +94,21 @@ void decompress_cat(enum compress_type type, int fd_in, int 
fd_out, char *desc,
       }
       exit(0);
 #else
-      fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", "-dc", v.buf);
+      fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", "-dc", NULL, v.buf);
 #endif
     case compress_type_lzma:
-      fd_fd_filter(fd_in, fd_out, LZMA, "lzma", "-dc", v.buf);
+      {
+        const char *path = getenv("PATH");
+        size_t bufsz = strlen(path) + 2 + strlen("xz");
+        char* buf = (char*)m_malloc(bufsz);
+
+        if (!path) ohshit(_("dpkg - error: PATH is not set.\n"));
+        if (path_findprog(path, "sz", buf, bufsz))
+          fd_fd_filter(fd_in, fd_out, LZMA,
+                       "xz", "--format=lzma", "-dc", v.buf);
+        else
+          fd_fd_filter(fd_in, fd_out, LZMA, "lzma", "-dc", NULL, v.buf);
+      }
     case compress_type_cat:
       fd_fd_copy(fd_in, fd_out, -1, _("%s: decompression"), v.buf);
       exit(0);
@@ -147,7 +164,7 @@ void compress_cat(enum compress_type type, int fd_in, int 
fd_out, const char *co
 #else
       strncpy(combuf, "-9c", sizeof(combuf));
       combuf[1]= *compression;
-      fd_fd_filter(fd_in, fd_out, GZIP, "gzip", combuf, v.buf);
+      fd_fd_filter(fd_in, fd_out, GZIP, "gzip", combuf, NULL, v.buf);
 #endif
     case compress_type_bzip2:
 #ifdef WITH_BZ2
@@ -182,12 +199,23 @@ void compress_cat(enum compress_type type, int fd_in, int 
fd_out, const char *co
 #else
       strncpy(combuf, "-9c", sizeof(combuf));
       combuf[1]= *compression;
-      fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", combuf, v.buf);
+      fd_fd_filter(fd_in, fd_out, BZIP2, "bzip2", combuf, NULL, v.buf);
 #endif
     case compress_type_lzma:
       strncpy(combuf, "-9c", sizeof(combuf));
       combuf[1] = *compression;
-      fd_fd_filter(fd_in, fd_out, LZMA, "lzma", combuf, v.buf);
+      {
+        const char *path = getenv("PATH");
+        size_t bufsz = strlen(path) + 2 + strlen("xz");
+        char* buf = (char*)m_malloc(bufsz);
+
+        if (!path) ohshit(_("dpkg - error: PATH is not set.\n"));
+        if (path_findprog(path, "sz", buf, bufsz))
+          fd_fd_filter(fd_in, fd_out, LZMA,
+                       "xz", "--format=lzma", combuf, v.buf);
+        else
+          fd_fd_filter(fd_in, fd_out, LZMA, "lzma", combuf, NULL, v.buf);
+      }
     case compress_type_cat:
       fd_fd_copy(fd_in, fd_out, -1, _("%s: compression"), v.buf);
       exit(0);
-- 
1.6.4.244.ge5cd0




-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to