mirror of
https://github.com/sheumann/hush.git
synced 2024-08-26 12:29:04 +00:00
Nore unarchive (and doc) fixes from Laurence Anderson
This commit is contained in:
parent
1557626897
commit
2e6d3cfa82
@ -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 \
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
7
cpio.c
7
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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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 \
|
||||
|
@ -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);
|
||||
|
@ -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 */
|
||||
|
6
usage.h
6
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 \
|
||||
|
Loading…
Reference in New Issue
Block a user