diff options
| author | Glenn L McGrath <bug1@ihug.co.nz> | 2001-06-24 12:36:54 +0000 |
|---|---|---|
| committer | Glenn L McGrath <bug1@ihug.co.nz> | 2001-06-24 12:36:54 +0000 |
| commit | 2e6d3cfa82eb64fffe53ccb5669aa7146228cf8f (patch) | |
| tree | 78fb21d71f9d8680422f85a00bc3045cd6185a99 | |
| parent | 15576268971168108f289cac6d6ecc6fdbb5075e (diff) | |
| download | busybox-w32-2e6d3cfa82eb64fffe53ccb5669aa7146228cf8f.tar.gz busybox-w32-2e6d3cfa82eb64fffe53ccb5669aa7146228cf8f.tar.bz2 busybox-w32-2e6d3cfa82eb64fffe53ccb5669aa7146228cf8f.zip | |
Nore unarchive (and doc) fixes from Laurence Anderson
| -rw-r--r-- | applets/usage.h | 6 | ||||
| -rw-r--r-- | archival/cpio.c | 7 | ||||
| -rw-r--r-- | archival/dpkg_deb.c | 2 | ||||
| -rw-r--r-- | cpio.c | 7 | ||||
| -rw-r--r-- | docs/new-applet-HOWTO.txt | 35 | ||||
| -rw-r--r-- | dpkg_deb.c | 2 | ||||
| -rw-r--r-- | include/libbb.h | 2 | ||||
| -rw-r--r-- | include/usage.h | 6 | ||||
| -rw-r--r-- | libbb/libbb.h | 2 | ||||
| -rw-r--r-- | libbb/unarchive.c | 24 | ||||
| -rw-r--r-- | usage.h | 6 |
11 files changed, 49 insertions, 50 deletions
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 @@ | |||
| 134 | #define cpio_full_usage \ | 134 | #define cpio_full_usage \ |
| 135 | "Extract or list files from a cpio archive\n" \ | 135 | "Extract or list files from a cpio archive\n" \ |
| 136 | "Main operation mode:\n" \ | 136 | "Main operation mode:\n" \ |
| 137 | "\td\t\tmake directories (assumed)\n" \ | 137 | "\td\t\tmake leading directories\n" \ |
| 138 | "\ti\t\textract\n" \ | 138 | "\ti\t\textract\n" \ |
| 139 | "\tm\t\tpreserve time\n" \ | 139 | "\tm\t\tpreserve mtime\n" \ |
| 140 | "\tt\t\tlist\n" \ | 140 | "\tt\t\tlist\n" \ |
| 141 | "\tu\t\tunconditional (assumed)\t" \ | 141 | "\tu\t\tunconditional overwrite\t" \ |
| 142 | "\tF\t\tinput from file\t" | 142 | "\tF\t\tinput from file\t" |
| 143 | 143 | ||
| 144 | #define cut_trivial_usage \ | 144 | #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 @@ | |||
| 21 | * Limitations: | 21 | * Limitations: |
| 22 | * Doesn't check CRC's | 22 | * Doesn't check CRC's |
| 23 | * Only supports new ASCII and CRC formats | 23 | * Only supports new ASCII and CRC formats |
| 24 | * Doesnt support hard links | ||
| 25 | * | 24 | * |
| 26 | */ | 25 | */ |
| 27 | #include <fcntl.h> | 26 | #include <fcntl.h> |
| @@ -45,9 +44,9 @@ extern int cpio_main(int argc, char **argv) | |||
| 45 | case 'i': // extract | 44 | case 'i': // extract |
| 46 | extract_function |= extract_all_to_fs; | 45 | extract_function |= extract_all_to_fs; |
| 47 | break; | 46 | break; |
| 48 | case 'd': // create directories | 47 | case 'd': // create _leading_ directories |
| 49 | extract_function |= extract_create_dirs; | 48 | extract_function |= extract_create_leading_dirs; |
| 50 | oldmask = umask(077); /* Make create_path act like GNU cpio */ | 49 | oldmask = umask(077); /* Make make_directory act like GNU cpio */ |
| 51 | break; | 50 | break; |
| 52 | case 'm': // preserve modification time | 51 | case 'm': // preserve modification time |
| 53 | extract_function |= extract_preserve_date; | 52 | 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) | |||
| 26 | char *output_buffer = NULL; | 26 | char *output_buffer = NULL; |
| 27 | int opt = 0; | 27 | int opt = 0; |
| 28 | int arg_type = 0; | 28 | int arg_type = 0; |
| 29 | int deb_extract_funct = extract_create_dirs | extract_unconditional; | 29 | int deb_extract_funct = extract_create_leading_dirs | extract_unconditional; |
| 30 | 30 | ||
| 31 | const int arg_type_prefix = 1; | 31 | const int arg_type_prefix = 1; |
| 32 | const int arg_type_field = 2; | 32 | const int arg_type_field = 2; |
| @@ -21,7 +21,6 @@ | |||
| 21 | * Limitations: | 21 | * Limitations: |
| 22 | * Doesn't check CRC's | 22 | * Doesn't check CRC's |
| 23 | * Only supports new ASCII and CRC formats | 23 | * Only supports new ASCII and CRC formats |
| 24 | * Doesnt support hard links | ||
| 25 | * | 24 | * |
| 26 | */ | 25 | */ |
| 27 | #include <fcntl.h> | 26 | #include <fcntl.h> |
| @@ -45,9 +44,9 @@ extern int cpio_main(int argc, char **argv) | |||
| 45 | case 'i': // extract | 44 | case 'i': // extract |
| 46 | extract_function |= extract_all_to_fs; | 45 | extract_function |= extract_all_to_fs; |
| 47 | break; | 46 | break; |
| 48 | case 'd': // create directories | 47 | case 'd': // create _leading_ directories |
| 49 | extract_function |= extract_create_dirs; | 48 | extract_function |= extract_create_leading_dirs; |
| 50 | oldmask = umask(077); /* Make create_path act like GNU cpio */ | 49 | oldmask = umask(077); /* Make make_directory act like GNU cpio */ |
| 51 | break; | 50 | break; |
| 52 | case 'm': // preserve modification time | 51 | case 'm': // preserve modification time |
| 53 | extract_function |= extract_preserve_date; | 52 | 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 | |||
| 70 | directory and make your program compliant. | 70 | directory and make your program compliant. |
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | Some Words on utility.c | 73 | Some Words on libbb |
| 74 | ----------------------- | 74 | ------------------- |
| 75 | 75 | ||
| 76 | As you are writing your applet, please be aware of the body of pre-existing | 76 | As you are writing your applet, please be aware of the body of pre-existing |
| 77 | useful functions in utility.c. Use these instead of reinventing the wheel. | 77 | useful functions in libbb. Use these instead of reinventing the wheel. |
| 78 | |||
| 79 | If you use functions from utility.c, you may need to add to the preprocessor | ||
| 80 | conditionals in that file, to make sure the routines you need are included. | ||
| 81 | So, since your mu implementation used safe_read(), append "|| defined BB_MU" to | ||
| 82 | the #if instruction that precedes the safe_read() function in utility.c . | ||
| 83 | 78 | ||
| 84 | Additionally, if you have any useful, general-purpose functions in your | 79 | Additionally, if you have any useful, general-purpose functions in your |
| 85 | program that could be useful in another program, consider putting them in | 80 | program that could be useful in another program, consider putting them in |
| 86 | utility.c. | 81 | libbb. |
| 87 | 82 | ||
| 88 | 83 | ||
| 89 | Usage String(s) | 84 | Usage String(s) |
| 90 | --------------- | 85 | --------------- |
| 91 | 86 | ||
| 92 | Next, add usage information for you applet to usage.c. This should look like | 87 | Next, add usage information for you applet to usage.h. This should look like |
| 93 | the following: | 88 | the following: |
| 94 | 89 | ||
| 95 | #if defined BB_MU | 90 | #define mu_trivial_usage \ |
| 96 | const char mu_usage[] = | 91 | "-[abcde] FILES" |
| 97 | "mu\n" | 92 | #define mu_full_usage \ |
| 98 | #ifndef BB_FEATURE_TRIVIAL_HELP | 93 | "Returns an indeterminate value.\n\n" \ |
| 99 | "\nReturns an indeterminate value.\n" | 94 | "Options:\n" \ |
| 100 | #endif | 95 | "\t-a\t\tfirst function\n" \ |
| 101 | ; | 96 | "\t-b\t\tsecond function\n" \ |
| 102 | 97 | ||
| 103 | If your program supports flags, the flags should be mentioned on the first | 98 | If your program supports flags, the flags should be mentioned on the first |
| 104 | line (mu -[bcRovma]) and a detailed description of each flag should go in the | 99 | line (-[abcde]) and a detailed description of each flag should go in the |
| 105 | BB_FEATURE_TRIVIAL_HELP section, one flag per line. (Numerous examples of this | 100 | mu_full_usage section, one flag per line. (Numerous examples of this |
| 106 | currently exist in usage.c.) | 101 | currently exist in usage.h.) |
| 107 | 102 | ||
| 108 | 103 | ||
| 109 | Header Files | 104 | 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) | |||
| 26 | char *output_buffer = NULL; | 26 | char *output_buffer = NULL; |
| 27 | int opt = 0; | 27 | int opt = 0; |
| 28 | int arg_type = 0; | 28 | int arg_type = 0; |
| 29 | int deb_extract_funct = extract_create_dirs | extract_unconditional; | 29 | int deb_extract_funct = extract_create_leading_dirs | extract_unconditional; |
| 30 | 30 | ||
| 31 | const int arg_type_prefix = 1; | 31 | const int arg_type_prefix = 1; |
| 32 | const int arg_type_field = 2; | 32 | 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 { | |||
| 227 | extract_control_tar_gz = 128, | 227 | extract_control_tar_gz = 128, |
| 228 | extract_unzip_only = 256, | 228 | extract_unzip_only = 256, |
| 229 | extract_unconditional = 512, | 229 | extract_unconditional = 512, |
| 230 | extract_create_dirs = 1024 | 230 | extract_create_leading_dirs = 1024 |
| 231 | }; | 231 | }; |
| 232 | char *unarchive(FILE *src_stream, void *(*get_header)(FILE *), | 232 | char *unarchive(FILE *src_stream, void *(*get_header)(FILE *), |
| 233 | const int extract_function, const char *prefix, char **extract_names); | 233 | 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 @@ | |||
| 134 | #define cpio_full_usage \ | 134 | #define cpio_full_usage \ |
| 135 | "Extract or list files from a cpio archive\n" \ | 135 | "Extract or list files from a cpio archive\n" \ |
| 136 | "Main operation mode:\n" \ | 136 | "Main operation mode:\n" \ |
| 137 | "\td\t\tmake directories (assumed)\n" \ | 137 | "\td\t\tmake leading directories\n" \ |
| 138 | "\ti\t\textract\n" \ | 138 | "\ti\t\textract\n" \ |
| 139 | "\tm\t\tpreserve time\n" \ | 139 | "\tm\t\tpreserve mtime\n" \ |
| 140 | "\tt\t\tlist\n" \ | 140 | "\tt\t\tlist\n" \ |
| 141 | "\tu\t\tunconditional (assumed)\t" \ | 141 | "\tu\t\tunconditional overwrite\t" \ |
| 142 | "\tF\t\tinput from file\t" | 142 | "\tF\t\tinput from file\t" |
| 143 | 143 | ||
| 144 | #define cut_trivial_usage \ | 144 | #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 { | |||
| 227 | extract_control_tar_gz = 128, | 227 | extract_control_tar_gz = 128, |
| 228 | extract_unzip_only = 256, | 228 | extract_unzip_only = 256, |
| 229 | extract_unconditional = 512, | 229 | extract_unconditional = 512, |
| 230 | extract_create_dirs = 1024 | 230 | extract_create_leading_dirs = 1024 |
| 231 | }; | 231 | }; |
| 232 | char *unarchive(FILE *src_stream, void *(*get_header)(FILE *), | 232 | char *unarchive(FILE *src_stream, void *(*get_header)(FILE *), |
| 233 | const int extract_function, const char *prefix, char **extract_names); | 233 | 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 | |||
| 129 | } | 129 | } |
| 130 | } else { | 130 | } else { |
| 131 | error_msg("%s not created: newer or same age file exists", file_entry->name); | 131 | error_msg("%s not created: newer or same age file exists", file_entry->name); |
| 132 | if (S_ISREG(file_entry->mode)) { | ||
| 133 | seek_sub_file(src_stream, file_entry->size); | 132 | seek_sub_file(src_stream, file_entry->size); |
| 134 | } | ||
| 135 | return (NULL); | 133 | return (NULL); |
| 136 | } | 134 | } |
| 137 | } | 135 | } |
| 136 | if (function & extract_create_leading_dirs) { /* Create leading directories with default umask */ | ||
| 137 | char *parent = dirname(full_name); | ||
| 138 | if (make_directory (parent, -1, FILEUTILS_RECUR) != 0) { | ||
| 139 | error_msg("couldn't create leading directories"); | ||
| 140 | } | ||
| 141 | free (parent); | ||
| 142 | } | ||
| 138 | switch(file_entry->mode & S_IFMT) { | 143 | switch(file_entry->mode & S_IFMT) { |
| 139 | case S_IFREG: | 144 | case S_IFREG: |
| 140 | if (file_entry->link_name) { /* Found a cpio hard link */ | 145 | 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 | |||
| 153 | } | 158 | } |
| 154 | break; | 159 | break; |
| 155 | case S_IFDIR: | 160 | case S_IFDIR: |
| 156 | if ((function & extract_create_dirs) && (stat_res != 0)) { | 161 | if (stat_res != 0) { |
| 157 | /* Make sure the prefix component of full_name was create | ||
| 158 | * in applet before getting here*/ | ||
| 159 | if (mkdir(full_name, file_entry->mode) < 0) { | 162 | if (mkdir(full_name, file_entry->mode) < 0) { |
| 160 | perror_msg("extract_archive: "); | 163 | perror_msg("extract_archive: "); |
| 161 | } | 164 | } |
| @@ -239,9 +242,6 @@ char *unarchive(FILE *src_stream, void *(*get_headers)(FILE *), | |||
| 239 | } | 242 | } |
| 240 | if (!found) { | 243 | if (!found) { |
| 241 | /* seek past the data entry */ | 244 | /* seek past the data entry */ |
| 242 | if (!S_ISLNK(file_entry->mode) && file_entry->link_name && file_entry->size == 0) { | ||
| 243 | error_msg("You should extract %s as other files are hardlinked to it", file_entry->name); | ||
| 244 | } | ||
| 245 | seek_sub_file(src_stream, file_entry->size); | 245 | seek_sub_file(src_stream, file_entry->size); |
| 246 | continue; | 246 | continue; |
| 247 | } | 247 | } |
| @@ -271,6 +271,7 @@ void *get_header_ar(FILE *src_stream) | |||
| 271 | static char *ar_long_names; | 271 | static char *ar_long_names; |
| 272 | 272 | ||
| 273 | if (fread(ar.raw, 1, 60, src_stream) != 60) { | 273 | if (fread(ar.raw, 1, 60, src_stream) != 60) { |
| 274 | free (ar_long_names); | ||
| 274 | return(NULL); | 275 | return(NULL); |
| 275 | } | 276 | } |
| 276 | archive_offset += 60; | 277 | archive_offset += 60; |
| @@ -308,7 +309,11 @@ void *get_header_ar(FILE *src_stream) | |||
| 308 | archive_offset += typed->size; | 309 | archive_offset += typed->size; |
| 309 | /* This ar entries data section only contained filenames for other records | 310 | /* This ar entries data section only contained filenames for other records |
| 310 | * they are stored in the static ar_long_names for future reference */ | 311 | * they are stored in the static ar_long_names for future reference */ |
| 311 | return(NULL); | 312 | return (get_header_ar(src_stream)); /* Return next header */ |
| 313 | } else if (ar.formated.name[1] == ' ') { | ||
| 314 | /* This is the index of symbols in the file for compilers */ | ||
| 315 | seek_sub_file(src_stream, typed->size); | ||
| 316 | return (get_header_ar(src_stream)); /* Return next header */ | ||
| 312 | } else { | 317 | } else { |
| 313 | /* The number after the '/' indicates the offset in the ar data section | 318 | /* The number after the '/' indicates the offset in the ar data section |
| 314 | (saved in variable long_name) that conatains the real filename */ | 319 | (saved in variable long_name) that conatains the real filename */ |
| @@ -413,6 +418,7 @@ void *get_header_cpio(FILE *src_stream) | |||
| 413 | cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1); | 418 | cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1); |
| 414 | fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream); | 419 | fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream); |
| 415 | archive_offset += cpio_entry->size; | 420 | archive_offset += cpio_entry->size; |
| 421 | cpio_entry->size = 0; /* Stop possiable seeks in future */ | ||
| 416 | } | 422 | } |
| 417 | if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) { | 423 | if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) { |
| 418 | if (cpio_entry->size == 0) { /* Put file on a linked list for later */ | 424 | if (cpio_entry->size == 0) { /* Put file on a linked list for later */ |
| @@ -134,11 +134,11 @@ | |||
| 134 | #define cpio_full_usage \ | 134 | #define cpio_full_usage \ |
| 135 | "Extract or list files from a cpio archive\n" \ | 135 | "Extract or list files from a cpio archive\n" \ |
| 136 | "Main operation mode:\n" \ | 136 | "Main operation mode:\n" \ |
| 137 | "\td\t\tmake directories (assumed)\n" \ | 137 | "\td\t\tmake leading directories\n" \ |
| 138 | "\ti\t\textract\n" \ | 138 | "\ti\t\textract\n" \ |
| 139 | "\tm\t\tpreserve time\n" \ | 139 | "\tm\t\tpreserve mtime\n" \ |
| 140 | "\tt\t\tlist\n" \ | 140 | "\tt\t\tlist\n" \ |
| 141 | "\tu\t\tunconditional (assumed)\t" \ | 141 | "\tu\t\tunconditional overwrite\t" \ |
| 142 | "\tF\t\tinput from file\t" | 142 | "\tF\t\tinput from file\t" |
| 143 | 143 | ||
| 144 | #define cut_trivial_usage \ | 144 | #define cut_trivial_usage \ |
