Nore unarchive (and doc) fixes from Laurence Anderson

This commit is contained in:
Glenn L McGrath 2001-06-24 12:36:54 +00:00
parent 1557626897
commit 2e6d3cfa82
11 changed files with 49 additions and 50 deletions

View File

@ -134,11 +134,11 @@
#define cpio_full_usage \ #define cpio_full_usage \
"Extract or list files from a cpio archive\n" \ "Extract or list files from a cpio archive\n" \
"Main operation mode:\n" \ "Main operation mode:\n" \
"\td\t\tmake directories (assumed)\n" \ "\td\t\tmake leading directories\n" \
"\ti\t\textract\n" \ "\ti\t\textract\n" \
"\tm\t\tpreserve time\n" \ "\tm\t\tpreserve mtime\n" \
"\tt\t\tlist\n" \ "\tt\t\tlist\n" \
"\tu\t\tunconditional (assumed)\t" \ "\tu\t\tunconditional overwrite\t" \
"\tF\t\tinput from file\t" "\tF\t\tinput from file\t"
#define cut_trivial_usage \ #define cut_trivial_usage \

View File

@ -21,7 +21,6 @@
* Limitations: * Limitations:
* Doesn't check CRC's * Doesn't check CRC's
* Only supports new ASCII and CRC formats * Only supports new ASCII and CRC formats
* Doesnt support hard links
* *
*/ */
#include <fcntl.h> #include <fcntl.h>
@ -45,9 +44,9 @@ extern int cpio_main(int argc, char **argv)
case 'i': // extract case 'i': // extract
extract_function |= extract_all_to_fs; extract_function |= extract_all_to_fs;
break; break;
case 'd': // create directories case 'd': // create _leading_ directories
extract_function |= extract_create_dirs; extract_function |= extract_create_leading_dirs;
oldmask = umask(077); /* Make create_path act like GNU cpio */ oldmask = umask(077); /* Make make_directory act like GNU cpio */
break; break;
case 'm': // preserve modification time case 'm': // preserve modification time
extract_function |= extract_preserve_date; extract_function |= extract_preserve_date;

View File

@ -26,7 +26,7 @@ extern int dpkg_deb_main(int argc, char **argv)
char *output_buffer = NULL; char *output_buffer = NULL;
int opt = 0; int opt = 0;
int arg_type = 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_prefix = 1;
const int arg_type_field = 2; const int arg_type_field = 2;

7
cpio.c
View File

@ -21,7 +21,6 @@
* Limitations: * Limitations:
* Doesn't check CRC's * Doesn't check CRC's
* Only supports new ASCII and CRC formats * Only supports new ASCII and CRC formats
* Doesnt support hard links
* *
*/ */
#include <fcntl.h> #include <fcntl.h>
@ -45,9 +44,9 @@ extern int cpio_main(int argc, char **argv)
case 'i': // extract case 'i': // extract
extract_function |= extract_all_to_fs; extract_function |= extract_all_to_fs;
break; break;
case 'd': // create directories case 'd': // create _leading_ directories
extract_function |= extract_create_dirs; extract_function |= extract_create_leading_dirs;
oldmask = umask(077); /* Make create_path act like GNU cpio */ oldmask = umask(077); /* Make make_directory act like GNU cpio */
break; break;
case 'm': // preserve modification time case 'm': // preserve modification time
extract_function |= extract_preserve_date; extract_function |= extract_preserve_date;

View File

@ -70,40 +70,35 @@ you _write_ your applet) please read through the style guide in the docs
directory and make your program compliant. 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 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. useful functions in libbb. 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 .
Additionally, if you have any useful, general-purpose functions in your Additionally, if you have any useful, general-purpose functions in your
program that could be useful in another program, consider putting them in program that could be useful in another program, consider putting them in
utility.c. libbb.
Usage String(s) 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: the following:
#if defined BB_MU #define mu_trivial_usage \
const char mu_usage[] = "-[abcde] FILES"
"mu\n" #define mu_full_usage \
#ifndef BB_FEATURE_TRIVIAL_HELP "Returns an indeterminate value.\n\n" \
"\nReturns an indeterminate value.\n" "Options:\n" \
#endif "\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 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 line (-[abcde]) and a detailed description of each flag should go in the
BB_FEATURE_TRIVIAL_HELP section, one flag per line. (Numerous examples of this mu_full_usage section, one flag per line. (Numerous examples of this
currently exist in usage.c.) currently exist in usage.h.)
Header Files Header Files

View File

@ -26,7 +26,7 @@ extern int dpkg_deb_main(int argc, char **argv)
char *output_buffer = NULL; char *output_buffer = NULL;
int opt = 0; int opt = 0;
int arg_type = 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_prefix = 1;
const int arg_type_field = 2; const int arg_type_field = 2;

View File

@ -227,7 +227,7 @@ enum extract_functions_e {
extract_control_tar_gz = 128, extract_control_tar_gz = 128,
extract_unzip_only = 256, extract_unzip_only = 256,
extract_unconditional = 512, extract_unconditional = 512,
extract_create_dirs = 1024 extract_create_leading_dirs = 1024
}; };
char *unarchive(FILE *src_stream, void *(*get_header)(FILE *), char *unarchive(FILE *src_stream, void *(*get_header)(FILE *),
const int extract_function, const char *prefix, char **extract_names); const int extract_function, const char *prefix, char **extract_names);

View File

@ -134,11 +134,11 @@
#define cpio_full_usage \ #define cpio_full_usage \
"Extract or list files from a cpio archive\n" \ "Extract or list files from a cpio archive\n" \
"Main operation mode:\n" \ "Main operation mode:\n" \
"\td\t\tmake directories (assumed)\n" \ "\td\t\tmake leading directories\n" \
"\ti\t\textract\n" \ "\ti\t\textract\n" \
"\tm\t\tpreserve time\n" \ "\tm\t\tpreserve mtime\n" \
"\tt\t\tlist\n" \ "\tt\t\tlist\n" \
"\tu\t\tunconditional (assumed)\t" \ "\tu\t\tunconditional overwrite\t" \
"\tF\t\tinput from file\t" "\tF\t\tinput from file\t"
#define cut_trivial_usage \ #define cut_trivial_usage \

View File

@ -227,7 +227,7 @@ enum extract_functions_e {
extract_control_tar_gz = 128, extract_control_tar_gz = 128,
extract_unzip_only = 256, extract_unzip_only = 256,
extract_unconditional = 512, extract_unconditional = 512,
extract_create_dirs = 1024 extract_create_leading_dirs = 1024
}; };
char *unarchive(FILE *src_stream, void *(*get_header)(FILE *), char *unarchive(FILE *src_stream, void *(*get_header)(FILE *),
const int extract_function, const char *prefix, char **extract_names); const int extract_function, const char *prefix, char **extract_names);

View File

@ -129,12 +129,17 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f
} }
} else { } else {
error_msg("%s not created: newer or same age file exists", file_entry->name); 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); seek_sub_file(src_stream, file_entry->size);
}
return (NULL); 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) { switch(file_entry->mode & S_IFMT) {
case S_IFREG: case S_IFREG:
if (file_entry->link_name) { /* Found a cpio hard link */ 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; break;
case S_IFDIR: case S_IFDIR:
if ((function & extract_create_dirs) && (stat_res != 0)) { if (stat_res != 0) {
/* Make sure the prefix component of full_name was create
* in applet before getting here*/
if (mkdir(full_name, file_entry->mode) < 0) { if (mkdir(full_name, file_entry->mode) < 0) {
perror_msg("extract_archive: "); perror_msg("extract_archive: ");
} }
@ -239,9 +242,6 @@ char *unarchive(FILE *src_stream, void *(*get_headers)(FILE *),
} }
if (!found) { if (!found) {
/* seek past the data entry */ /* 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); seek_sub_file(src_stream, file_entry->size);
continue; continue;
} }
@ -271,6 +271,7 @@ void *get_header_ar(FILE *src_stream)
static char *ar_long_names; static char *ar_long_names;
if (fread(ar.raw, 1, 60, src_stream) != 60) { if (fread(ar.raw, 1, 60, src_stream) != 60) {
free (ar_long_names);
return(NULL); return(NULL);
} }
archive_offset += 60; archive_offset += 60;
@ -308,7 +309,11 @@ void *get_header_ar(FILE *src_stream)
archive_offset += typed->size; archive_offset += typed->size;
/* This ar entries data section only contained filenames for other records /* This ar entries data section only contained filenames for other records
* they are stored in the static ar_long_names for future reference */ * 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 { } else {
/* The number after the '/' indicates the offset in the ar data section /* The number after the '/' indicates the offset in the ar data section
(saved in variable long_name) that conatains the real filename */ (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); cpio_entry->link_name = (char *) xcalloc(1, cpio_entry->size + 1);
fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream); fread(cpio_entry->link_name, 1, cpio_entry->size, src_stream);
archive_offset += cpio_entry->size; archive_offset += cpio_entry->size;
cpio_entry->size = 0; /* Stop possiable seeks in future */
} }
if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) { if (nlink > 1 && !S_ISDIR(cpio_entry->mode)) {
if (cpio_entry->size == 0) { /* Put file on a linked list for later */ if (cpio_entry->size == 0) { /* Put file on a linked list for later */

View File

@ -134,11 +134,11 @@
#define cpio_full_usage \ #define cpio_full_usage \
"Extract or list files from a cpio archive\n" \ "Extract or list files from a cpio archive\n" \
"Main operation mode:\n" \ "Main operation mode:\n" \
"\td\t\tmake directories (assumed)\n" \ "\td\t\tmake leading directories\n" \
"\ti\t\textract\n" \ "\ti\t\textract\n" \
"\tm\t\tpreserve time\n" \ "\tm\t\tpreserve mtime\n" \
"\tt\t\tlist\n" \ "\tt\t\tlist\n" \
"\tu\t\tunconditional (assumed)\t" \ "\tu\t\tunconditional overwrite\t" \
"\tF\t\tinput from file\t" "\tF\t\tinput from file\t"
#define cut_trivial_usage \ #define cut_trivial_usage \