Nore unarchive (and doc) fixes from Laurence Anderson
authorGlenn L McGrath <bug1@ihug.co.nz>
Sun, 24 Jun 2001 12:36:54 +0000 (12:36 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Sun, 24 Jun 2001 12:36:54 +0000 (12:36 -0000)
applets/usage.h
archival/cpio.c
archival/dpkg_deb.c
cpio.c
docs/new-applet-HOWTO.txt
dpkg_deb.c
include/libbb.h
include/usage.h
libbb/libbb.h
libbb/unarchive.c
usage.h

index 51a06b9774381563d53df798b5df1aedb7559120..bf10e114ffd6d945c8c20cbd4b472ec79ad5c0ed 100644 (file)
 #define cpio_full_usage \
        "Extract or list files from a cpio archive\n" \
        "Main operation mode:\n" \
-       "\td\t\tmake directories (assumed)\n" \
+       "\td\t\tmake leading directories\n" \
        "\ti\t\textract\n" \
-       "\tm\t\tpreserve time\n" \
+       "\tm\t\tpreserve mtime\n" \
        "\tt\t\tlist\n" \
-       "\tu\t\tunconditional (assumed)\t" \
+       "\tu\t\tunconditional overwrite\t" \
        "\tF\t\tinput from file\t"
        
 #define cut_trivial_usage \
index ecd6f534a7769c73ac4f671a6d5cb48b2f6f3049..101d6ec49bb65a7a10e7fce4e5f583e94e918713 100644 (file)
@@ -21,7 +21,6 @@
  * Limitations:
  *             Doesn't check CRC's
  *             Only supports new ASCII and CRC formats
- *             Doesnt support hard links
  *
  */
 #include <fcntl.h>
@@ -45,9 +44,9 @@ extern int cpio_main(int argc, char **argv)
                case 'i': // extract
                        extract_function |= extract_all_to_fs;
                        break;
-               case 'd': // create directories
-                       extract_function |= extract_create_dirs;
-                       oldmask = umask(077); /* Make create_path act like GNU cpio */
+               case 'd': // create _leading_ directories
+                       extract_function |= extract_create_leading_dirs;
+                       oldmask = umask(077); /* Make make_directory act like GNU cpio */
                        break;
                case 'm': // preserve modification time
                        extract_function |= extract_preserve_date;
index b1cbb1bbcb264bf3a38c61f87c77df19e3df91c9..7f4dcbf01b1250183c52fc1c857b721e105258af 100644 (file)
@@ -26,7 +26,7 @@ extern int dpkg_deb_main(int argc, char **argv)
        char *output_buffer = NULL;
        int opt = 0;
        int arg_type = 0;
-       int deb_extract_funct = extract_create_dirs | extract_unconditional;    
+       int deb_extract_funct = extract_create_leading_dirs | extract_unconditional;    
        
        const int arg_type_prefix = 1;
        const int arg_type_field = 2;
diff --git a/cpio.c b/cpio.c
index ecd6f534a7769c73ac4f671a6d5cb48b2f6f3049..101d6ec49bb65a7a10e7fce4e5f583e94e918713 100644 (file)
--- a/cpio.c
+++ b/cpio.c
@@ -21,7 +21,6 @@
  * Limitations:
  *             Doesn't check CRC's
  *             Only supports new ASCII and CRC formats
- *             Doesnt support hard links
  *
  */
 #include <fcntl.h>
@@ -45,9 +44,9 @@ extern int cpio_main(int argc, char **argv)
                case 'i': // extract
                        extract_function |= extract_all_to_fs;
                        break;
-               case 'd': // create directories
-                       extract_function |= extract_create_dirs;
-                       oldmask = umask(077); /* Make create_path act like GNU cpio */
+               case 'd': // create _leading_ directories
+                       extract_function |= extract_create_leading_dirs;
+                       oldmask = umask(077); /* Make make_directory act like GNU cpio */
                        break;
                case 'm': // preserve modification time
                        extract_function |= extract_preserve_date;
index 90e124d01cb8dcd7fe155edddb48035348241f03..1f5c3ebd5318e772d50f3d423ee129394e4a4ca9 100644 (file)
@@ -70,40 +70,35 @@ you _write_ your applet) please read through the style guide in the docs
 directory and make your program compliant.
 
 
-Some Words on utility.c
------------------------
+Some Words on libbb
+-------------------
 
 As you are writing your applet, please be aware of the body of pre-existing
-useful functions in utility.c. Use these instead of reinventing the wheel.
-
-If you use functions from utility.c, you may need to add to the preprocessor
-conditionals in that file, to make sure the routines you need are included.
-So, since your mu implementation used safe_read(), append "|| defined BB_MU" to
-the #if instruction that precedes the safe_read() function in utility.c .
+useful functions in libbb. Use these instead of reinventing the wheel.
 
 Additionally, if you have any useful, general-purpose functions in your
 program that could be useful in another program, consider putting them in
-utility.c.
+libbb.
 
 
 Usage String(s)
 ---------------
 
-Next, add usage information for you applet to usage.c. This should look like
+Next, add usage information for you applet to usage.h. This should look like
 the following:
 
-       #if defined BB_MU
-       const char mu_usage[] =
-               "mu\n"
-       #ifndef BB_FEATURE_TRIVIAL_HELP
-               "\nReturns an indeterminate value.\n"
-       #endif
-               ;
+       #define mu_trivial_usage \
+               "-[abcde] FILES"
+       #define mu_full_usage \
+               "Returns an indeterminate value.\n\n" \
+               "Options:\n" \
+               "\t-a\t\tfirst function\n" \
+               "\t-b\t\tsecond function\n" \
 
 If your program supports flags, the flags should be mentioned on the first
-line (mu -[bcRovma]) and a detailed description of each flag should go in the
-BB_FEATURE_TRIVIAL_HELP section, one flag per line. (Numerous examples of this
-currently exist in usage.c.)
+line (-[abcde]) and a detailed description of each flag should go in the
+mu_full_usage section, one flag per line. (Numerous examples of this
+currently exist in usage.h.)
 
 
 Header Files
index b1cbb1bbcb264bf3a38c61f87c77df19e3df91c9..7f4dcbf01b1250183c52fc1c857b721e105258af 100644 (file)
@@ -26,7 +26,7 @@ extern int dpkg_deb_main(int argc, char **argv)
        char *output_buffer = NULL;
        int opt = 0;
        int arg_type = 0;
-       int deb_extract_funct = extract_create_dirs | extract_unconditional;    
+       int deb_extract_funct = extract_create_leading_dirs | extract_unconditional;    
        
        const int arg_type_prefix = 1;
        const int arg_type_field = 2;
index a547953a1b3bed82f28f52fac2e12866f3e79972..102596c1fa67a9922d00d62d42ea79d0fc70f090 100644 (file)
@@ -227,7 +227,7 @@ enum extract_functions_e {
        extract_control_tar_gz = 128,
        extract_unzip_only = 256,
        extract_unconditional = 512,
-       extract_create_dirs = 1024
+       extract_create_leading_dirs = 1024
 };
 char *unarchive(FILE *src_stream, void *(*get_header)(FILE *),
        const int extract_function, const char *prefix, char **extract_names);
index 51a06b9774381563d53df798b5df1aedb7559120..bf10e114ffd6d945c8c20cbd4b472ec79ad5c0ed 100644 (file)
 #define cpio_full_usage \
        "Extract or list files from a cpio archive\n" \
        "Main operation mode:\n" \
-       "\td\t\tmake directories (assumed)\n" \
+       "\td\t\tmake leading directories\n" \
        "\ti\t\textract\n" \
-       "\tm\t\tpreserve time\n" \
+       "\tm\t\tpreserve mtime\n" \
        "\tt\t\tlist\n" \
-       "\tu\t\tunconditional (assumed)\t" \
+       "\tu\t\tunconditional overwrite\t" \
        "\tF\t\tinput from file\t"
        
 #define cut_trivial_usage \
index a547953a1b3bed82f28f52fac2e12866f3e79972..102596c1fa67a9922d00d62d42ea79d0fc70f090 100644 (file)
@@ -227,7 +227,7 @@ enum extract_functions_e {
        extract_control_tar_gz = 128,
        extract_unzip_only = 256,
        extract_unconditional = 512,
-       extract_create_dirs = 1024
+       extract_create_leading_dirs = 1024
 };
 char *unarchive(FILE *src_stream, void *(*get_header)(FILE *),
        const int extract_function, const char *prefix, char **extract_names);
index 20609ded7ff75173ab2ce2f5e5a8e5a85bcb8a3d..4847aab6b8f7b897d6c82d705917710f8210a93c 100644 (file)
@@ -129,12 +129,17 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f
                                }
                        } else {
                                error_msg("%s not created: newer or same age file exists", file_entry->name);
-                               if (S_ISREG(file_entry->mode)) {
                                        seek_sub_file(src_stream, file_entry->size);
-                               }
                                return (NULL);
                        }
                }
+               if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */
+                       char *parent = dirname(full_name);
+                       if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) {
+                               error_msg("couldn't create leading directories");
+                       }
+                       free (parent);
+               }
                switch(file_entry->mode & S_IFMT) {
                        case S_IFREG:
                                if (file_entry->link_name) { /* Found a cpio hard link */
@@ -153,9 +158,7 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f
                                }
                                break;
                        case S_IFDIR:
-                               if ((function & extract_create_dirs) && (stat_res != 0)) {
-                                       /* Make sure the prefix component of full_name was create
-                                        * in applet before getting here*/
+                               if (stat_res != 0) {
                                        if (mkdir(full_name, file_entry->mode) < 0) {
                                                perror_msg("extract_archive: ");
                                        }
@@ -239,9 +242,6 @@ char *unarchive(FILE *src_stream, void *(*get_headers)(FILE *),
                        }
                        if (!found) {
                                /* seek past the data entry */
-                               if (!S_ISLNK(file_entry->mode) && file_entry->link_name && file_entry->size == 0) {
-                                       error_msg("You should extract %s as other files are hardlinked to it", file_entry->name);
-                               }
                                seek_sub_file(src_stream, file_entry->size);
                                continue;
                        }
@@ -271,6 +271,7 @@ void *get_header_ar(FILE *src_stream)
        static char *ar_long_names;
 
        if (fread(ar.raw, 1, 60, src_stream) != 60) {
+               free (ar_long_names);
                return(NULL);
        }
        archive_offset += 60;
@@ -308,7 +309,11 @@ void *get_header_ar(FILE *src_stream)
                        archive_offset += typed->size;
                        /* This ar entries data section only contained filenames for other records
                         * they are stored in the static ar_long_names for future reference */
-                       return(NULL);
+                       return (get_header_ar(src_stream)); /* Return next header */
+               } else if (ar.formated.name[1] == ' ') {
+                       /* This is the index of symbols in the file for compilers */
+                       seek_sub_file(src_stream, typed->size);
+                       return (get_header_ar(src_stream)); /* Return next header */
                } else {
                        /* The number after the '/' indicates the offset in the ar data section
                        (saved in variable long_name) that conatains the real filename */
@@ -413,6 +418,7 @@ void *get_header_cpio(FILE *src_stream)
                                        cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1);
                                        fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream);
                                        archive_offset += cpio_entry->size;
+                                       cpio_entry->size = 0; /* Stop possiable seeks in future */
                                }
                                if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) {
                                        if (cpio_entry->size == 0) { /* Put file on a linked list for later */
diff --git a/usage.h b/usage.h
index 51a06b9774381563d53df798b5df1aedb7559120..bf10e114ffd6d945c8c20cbd4b472ec79ad5c0ed 100644 (file)
--- a/usage.h
+++ b/usage.h
 #define cpio_full_usage \
        "Extract or list files from a cpio archive\n" \
        "Main operation mode:\n" \
-       "\td\t\tmake directories (assumed)\n" \
+       "\td\t\tmake leading directories\n" \
        "\ti\t\textract\n" \
-       "\tm\t\tpreserve time\n" \
+       "\tm\t\tpreserve mtime\n" \
        "\tt\t\tlist\n" \
-       "\tu\t\tunconditional (assumed)\t" \
+       "\tu\t\tunconditional overwrite\t" \
        "\tF\t\tinput from file\t"
        
 #define cut_trivial_usage \