From: Glenn L McGrath Date: Sun, 24 Jun 2001 12:36:54 +0000 (-0000) Subject: Nore unarchive (and doc) fixes from Laurence Anderson X-Git-Tag: 0_52~68 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=2e6d3cfa82eb64fffe53ccb5669aa7146228cf8f;p=oweals%2Fbusybox.git Nore unarchive (and doc) fixes from Laurence Anderson --- diff --git a/applets/usage.h b/applets/usage.h index 51a06b977..bf10e114f 100644 --- a/applets/usage.h +++ b/applets/usage.h @@ -134,11 +134,11 @@ #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 \ diff --git a/archival/cpio.c b/archival/cpio.c index ecd6f534a..101d6ec49 100644 --- a/archival/cpio.c +++ b/archival/cpio.c @@ -21,7 +21,6 @@ * Limitations: * Doesn't check CRC's * Only supports new ASCII and CRC formats - * Doesnt support hard links * */ #include @@ -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; diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index b1cbb1bbc..7f4dcbf01 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c @@ -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 ecd6f534a..101d6ec49 100644 --- 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 @@ -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; diff --git a/docs/new-applet-HOWTO.txt b/docs/new-applet-HOWTO.txt index 90e124d01..1f5c3ebd5 100644 --- a/docs/new-applet-HOWTO.txt +++ b/docs/new-applet-HOWTO.txt @@ -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 diff --git a/dpkg_deb.c b/dpkg_deb.c index b1cbb1bbc..7f4dcbf01 100644 --- a/dpkg_deb.c +++ b/dpkg_deb.c @@ -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/include/libbb.h b/include/libbb.h index a547953a1..102596c1f 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -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); diff --git a/include/usage.h b/include/usage.h index 51a06b977..bf10e114f 100644 --- a/include/usage.h +++ b/include/usage.h @@ -134,11 +134,11 @@ #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 \ diff --git a/libbb/libbb.h b/libbb/libbb.h index a547953a1..102596c1f 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h @@ -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); diff --git a/libbb/unarchive.c b/libbb/unarchive.c index 20609ded7..4847aab6b 100644 --- a/libbb/unarchive.c +++ b/libbb/unarchive.c @@ -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 51a06b977..bf10e114f 100644 --- a/usage.h +++ b/usage.h @@ -134,11 +134,11 @@ #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 \