New dpkg-deb function -t, stands for --fsys-tarfile
authorGlenn L McGrath <bug1@ihug.co.nz>
Thu, 12 Apr 2001 13:49:09 +0000 (13:49 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Thu, 12 Apr 2001 13:49:09 +0000 (13:49 -0000)
applets/usage.h
archival/dpkg_deb.c
dpkg_deb.c
include/usage.h
libbb/deb_extract.c
libbb/untar.c
usage.h

index 5712c44133526d41af82a5fdadc2c1a3908454a6..31c749e2feead1542a77ace5ba6d2711f1361b61 100644 (file)
        "WORK IN PROGRESS, only usefull for debian-installer"
 
 #define dpkg_deb_trivial_usage \
-       "[-cexX] file directory"
+       "[-cefxX] file directory"
 #define dpkg_deb_full_usage \
        "Perform actions on debian packages (.debs)\n\n" \
        "Options:\n" \
-       "\t-c\tList contents of filesystem tree (verbose)\n" \
-       "\t-l\tList contents of filesystem tree (.list format)\n" \
+       "\t-c\tList contents of filesystem tree\n" \
        "\t-e\tExtract control files to directory\n" \
+       "\t-f\tExtract filesystem tree to stdout in tar format\n" \
        "\t-x\tExctract packages filesystem tree to directory\n" \
        "\t-X\tVerbose extract"
 #define dpkg_deb_example_usage \
index 6653f2a7cf83e002de490dd576c6b2516d5bdbc4..3bec8cfc79e1dd090f0f050f5c04a5d1efe66d93 100644 (file)
@@ -24,7 +24,7 @@ extern int dpkg_deb_main(int argc, char **argv)
        int opt = 0;
        int optflag = 0;        
        
-       while ((opt = getopt(argc, argv, "cexXl")) != -1) {
+       while ((opt = getopt(argc, argv, "cetXxl")) != -1) {
                switch (opt) {
                        case 'c':
                                optflag |= extract_contents;
@@ -32,6 +32,9 @@ extern int dpkg_deb_main(int argc, char **argv)
                        case 'e':
                                optflag |= extract_control;
                                break;
+                       case 't':
+                               optflag |= extract_fsys_tarfile;
+                               break;
                        case 'X':
                                optflag |= extract_verbose_extract;
                                break;
index 6653f2a7cf83e002de490dd576c6b2516d5bdbc4..3bec8cfc79e1dd090f0f050f5c04a5d1efe66d93 100644 (file)
@@ -24,7 +24,7 @@ extern int dpkg_deb_main(int argc, char **argv)
        int opt = 0;
        int optflag = 0;        
        
-       while ((opt = getopt(argc, argv, "cexXl")) != -1) {
+       while ((opt = getopt(argc, argv, "cetXxl")) != -1) {
                switch (opt) {
                        case 'c':
                                optflag |= extract_contents;
@@ -32,6 +32,9 @@ extern int dpkg_deb_main(int argc, char **argv)
                        case 'e':
                                optflag |= extract_control;
                                break;
+                       case 't':
+                               optflag |= extract_fsys_tarfile;
+                               break;
                        case 'X':
                                optflag |= extract_verbose_extract;
                                break;
index 5712c44133526d41af82a5fdadc2c1a3908454a6..31c749e2feead1542a77ace5ba6d2711f1361b61 100644 (file)
        "WORK IN PROGRESS, only usefull for debian-installer"
 
 #define dpkg_deb_trivial_usage \
-       "[-cexX] file directory"
+       "[-cefxX] file directory"
 #define dpkg_deb_full_usage \
        "Perform actions on debian packages (.debs)\n\n" \
        "Options:\n" \
-       "\t-c\tList contents of filesystem tree (verbose)\n" \
-       "\t-l\tList contents of filesystem tree (.list format)\n" \
+       "\t-c\tList contents of filesystem tree\n" \
        "\t-e\tExtract control files to directory\n" \
+       "\t-f\tExtract filesystem tree to stdout in tar format\n" \
        "\t-x\tExctract packages filesystem tree to directory\n" \
        "\t-X\tVerbose extract"
 #define dpkg_deb_example_usage \
index e982c14bb1248788950f85c4a96658d3cbd1c2d9..d3e615305e6086c2821915758fe39161db23314a 100644 (file)
@@ -26,6 +26,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <string.h>
 #include <signal.h>
 #include "libbb.h"
 
@@ -42,14 +43,9 @@ extern int deb_extract(const char *package_filename, int function, char *target_
                case (extract_control):
                        ared_file = xstrdup("control.tar.gz");
                        break;
-               case (extract_contents):
-               case (extract_extract):
-               case (extract_verbose_extract):
-               case (extract_list):
+               default:
                        ared_file = xstrdup("data.tar.gz");
                        break;
-               default:
-                       error_msg("Unknown extraction function");
        }
 
        /* open the debian package to be worked on */
@@ -71,9 +67,11 @@ extern int deb_extract(const char *package_filename, int function, char *target_
        /* open a stream of decompressed data */
        uncompressed_file = fdopen(gz_open(deb_file, &gunzip_pid), "r");
 
-       /* get a list of all tar headers inside the .gz file */
-       untar(uncompressed_file, function, target_dir);
-
+       if (function & extract_fsys_tarfile) {
+               copy_file_chunk(uncompressed_file, stdout, -1);
+       } else {
+               untar(uncompressed_file, function, target_dir);
+       }
        /* we are deliberately terminating the child so we can safely ignore this */
        gz_close(gunzip_pid);
 
index 9f7bd303cd44ff406afca0b263ba3071dbddae7e..11c55df7cb43b3d24f96c4971373dea111f9b866 100644 (file)
@@ -55,13 +55,26 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
        while (fread((char *) &raw_tar_header, 1, 512, src_tar_file) == 512) {
                long sum = 0;
                char *dir = NULL;
+               
+               if (ferror(src_tar_file) || feof(src_tar_file)) {
+                       break;
+               }
 
                uncompressed_count += 512;
 
                /* Check header has valid magic */
                if (strncmp(raw_tar_header.magic, "ustar", 5) != 0) {
-                       /* Put this pack after TODO (check child still alive) is done */
-                       error_msg("Invalid tar magic");
+/*
+ * FIXME, Need HELP with this
+ *
+ * This has to fail silently or it incorrectly reports errors when called from
+ * deb_extract.
+ * The problem is deb_extract decompresses the .gz file in a child process and
+ * untar reads from the child proccess. The child process finishes and exits,
+ * but fread reads 0's from the src_tar_file even though the child
+ * closed its handle.
+ */
+//                     error_msg("Invalid tar magic");
                        break;
                }
 
@@ -109,7 +122,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
 
                }
 */
-               if (untar_function & (extract_verbose_extract | extract_contents)) {
+               if (untar_function & (extract_contents | extract_verbose_extract)) {
                        printf("%s\n", raw_tar_header.name);
                }
 
@@ -144,7 +157,7 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path)
                                        break;
                                }
                        case '5':
-                               if (untar_function & (extract_extract | extract_verbose_extract)) {
+                               if (untar_function & extract_extract) {
                                        if (create_path(dir, mode) != TRUE) {
                                                free(dir);
                                                perror_msg("%s: Cannot mkdir", raw_tar_header.name); 
diff --git a/usage.h b/usage.h
index 5712c44133526d41af82a5fdadc2c1a3908454a6..31c749e2feead1542a77ace5ba6d2711f1361b61 100644 (file)
--- a/usage.h
+++ b/usage.h
        "WORK IN PROGRESS, only usefull for debian-installer"
 
 #define dpkg_deb_trivial_usage \
-       "[-cexX] file directory"
+       "[-cefxX] file directory"
 #define dpkg_deb_full_usage \
        "Perform actions on debian packages (.debs)\n\n" \
        "Options:\n" \
-       "\t-c\tList contents of filesystem tree (verbose)\n" \
-       "\t-l\tList contents of filesystem tree (.list format)\n" \
+       "\t-c\tList contents of filesystem tree\n" \
        "\t-e\tExtract control files to directory\n" \
+       "\t-f\tExtract filesystem tree to stdout in tar format\n" \
        "\t-x\tExctract packages filesystem tree to directory\n" \
        "\t-X\tVerbose extract"
 #define dpkg_deb_example_usage \