Allow the unarchive() extract_list variable to be NULL, meaning extract all
This commit is contained in:
parent
58a5bd187d
commit
a868ec89e8
10
ar.c
10
ar.c
@ -70,17 +70,17 @@ extern int ar_main(int argc, char **argv)
|
|||||||
|
|
||||||
/* check ar magic */
|
/* check ar magic */
|
||||||
fread(ar_magic, 1, 8, src_stream);
|
fread(ar_magic, 1, 8, src_stream);
|
||||||
|
archive_offset = 8;
|
||||||
if (strncmp(ar_magic,"!<arch>",7) != 0) {
|
if (strncmp(ar_magic,"!<arch>",7) != 0) {
|
||||||
error_msg_and_die("invalid magic");
|
error_msg_and_die("invalid magic");
|
||||||
}
|
}
|
||||||
archive_offset = 8;
|
|
||||||
|
|
||||||
extract_names = malloc(sizeof(char *));
|
/* Create a list of files to extract */
|
||||||
extract_names[0] = NULL;
|
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
|
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
|
||||||
|
extract_names[num_of_entries] = xstrdup(argv[optind]);
|
||||||
num_of_entries++;
|
num_of_entries++;
|
||||||
*extract_names = realloc(*extract_names, num_of_entries);
|
extract_names[num_of_entries] = NULL;
|
||||||
extract_names[num_of_entries - 1] = xstrdup(argv[optind]);
|
|
||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,17 +70,17 @@ extern int ar_main(int argc, char **argv)
|
|||||||
|
|
||||||
/* check ar magic */
|
/* check ar magic */
|
||||||
fread(ar_magic, 1, 8, src_stream);
|
fread(ar_magic, 1, 8, src_stream);
|
||||||
|
archive_offset = 8;
|
||||||
if (strncmp(ar_magic,"!<arch>",7) != 0) {
|
if (strncmp(ar_magic,"!<arch>",7) != 0) {
|
||||||
error_msg_and_die("invalid magic");
|
error_msg_and_die("invalid magic");
|
||||||
}
|
}
|
||||||
archive_offset = 8;
|
|
||||||
|
|
||||||
extract_names = malloc(sizeof(char *));
|
/* Create a list of files to extract */
|
||||||
extract_names[0] = NULL;
|
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
|
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
|
||||||
|
extract_names[num_of_entries] = xstrdup(argv[optind]);
|
||||||
num_of_entries++;
|
num_of_entries++;
|
||||||
*extract_names = realloc(*extract_names, num_of_entries);
|
extract_names[num_of_entries] = NULL;
|
||||||
extract_names[num_of_entries - 1] = xstrdup(argv[optind]);
|
|
||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,25 +68,28 @@ extern int cpio_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extract_function & extract_all_to_fs && extract_function & extract_list) {
|
if ((extract_function & extract_all_to_fs) && (extract_function & extract_list)) {
|
||||||
extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/
|
extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extract_function & extract_all_to_fs && extract_function & extract_verbose_list) { /* The meaning of v changes on extract */
|
if ((extract_function & extract_all_to_fs) && (extract_function & extract_verbose_list)) {
|
||||||
|
/* The meaning of v changes on extract */
|
||||||
extract_function ^= extract_verbose_list;
|
extract_function ^= extract_verbose_list;
|
||||||
extract_function |= extract_list;
|
extract_function |= extract_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_names = malloc(4);
|
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
|
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
|
||||||
|
extract_names[num_of_entries] = xstrdup(argv[optind]);
|
||||||
num_of_entries++;
|
num_of_entries++;
|
||||||
*extract_names = realloc(*extract_names, num_of_entries);
|
extract_names[num_of_entries] = NULL;
|
||||||
extract_names[num_of_entries - 1] = xstrdup(argv[optind]);
|
|
||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names);
|
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names);
|
||||||
if (oldmask) umask(oldmask); /* Restore umask if we changed it */
|
if (oldmask) {
|
||||||
|
umask(oldmask); /* Restore umask if we changed it */
|
||||||
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
cpio.c
15
cpio.c
@ -68,25 +68,28 @@ extern int cpio_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extract_function & extract_all_to_fs && extract_function & extract_list) {
|
if ((extract_function & extract_all_to_fs) && (extract_function & extract_list)) {
|
||||||
extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/
|
extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extract_function & extract_all_to_fs && extract_function & extract_verbose_list) { /* The meaning of v changes on extract */
|
if ((extract_function & extract_all_to_fs) && (extract_function & extract_verbose_list)) {
|
||||||
|
/* The meaning of v changes on extract */
|
||||||
extract_function ^= extract_verbose_list;
|
extract_function ^= extract_verbose_list;
|
||||||
extract_function |= extract_list;
|
extract_function |= extract_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
extract_names = malloc(4);
|
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
|
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
|
||||||
|
extract_names[num_of_entries] = xstrdup(argv[optind]);
|
||||||
num_of_entries++;
|
num_of_entries++;
|
||||||
*extract_names = realloc(*extract_names, num_of_entries);
|
extract_names[num_of_entries] = NULL;
|
||||||
extract_names[num_of_entries - 1] = xstrdup(argv[optind]);
|
|
||||||
optind++;
|
optind++;
|
||||||
}
|
}
|
||||||
|
|
||||||
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names);
|
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names);
|
||||||
if (oldmask) umask(oldmask); /* Restore umask if we changed it */
|
if (oldmask) {
|
||||||
|
umask(oldmask); /* Restore umask if we changed it */
|
||||||
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,25 +232,24 @@ char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers
|
|||||||
int i;
|
int i;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
|
|
||||||
if (extract_names == NULL) {
|
|
||||||
return(NULL);
|
|
||||||
}
|
|
||||||
archive_offset = 0;
|
archive_offset = 0;
|
||||||
while ((file_entry = get_headers(src_stream)) != NULL) {
|
while ((file_entry = get_headers(src_stream)) != NULL) {
|
||||||
found = FALSE;
|
found = FALSE;
|
||||||
if (extract_names[0] != NULL) {
|
if (extract_names == NULL) {
|
||||||
|
found = TRUE;
|
||||||
|
} else {
|
||||||
for(i = 0; extract_names[i] != 0; i++) {
|
for(i = 0; extract_names[i] != 0; i++) {
|
||||||
if (strcmp(extract_names[i], file_entry->name) == 0) {
|
if (strcmp(extract_names[i], file_entry->name) == 0) {
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
|
||||||
/* seek past the data entry */
|
|
||||||
seek_sub_file(src_stream, file_entry->size);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
buffer = extract_archive(src_stream, out_stream, file_entry, extract_function, prefix);
|
if (found) {
|
||||||
|
buffer = extract_archive(src_stream, out_stream, file_entry, extract_function, prefix);
|
||||||
|
} else {
|
||||||
|
/* seek past the data entry */
|
||||||
|
seek_sub_file(src_stream, file_entry->size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return(buffer);
|
return(buffer);
|
||||||
}
|
}
|
||||||
@ -544,17 +543,14 @@ char *deb_extract(const char *package_filename, FILE *out_stream,
|
|||||||
FILE *deb_stream;
|
FILE *deb_stream;
|
||||||
FILE *uncompressed_stream = NULL;
|
FILE *uncompressed_stream = NULL;
|
||||||
file_header_t *ar_header = NULL;
|
file_header_t *ar_header = NULL;
|
||||||
|
char **file_list = NULL;
|
||||||
char *output_buffer = NULL;
|
char *output_buffer = NULL;
|
||||||
char *ared_file = NULL;
|
char *ared_file = NULL;
|
||||||
char ar_magic[8];
|
char ar_magic[8];
|
||||||
char **file_list;
|
|
||||||
int gunzip_pid;
|
int gunzip_pid;
|
||||||
|
|
||||||
if (filename == NULL) {
|
if (filename != NULL) {
|
||||||
file_list = xmalloc(sizeof(char *));
|
file_list = xmalloc(sizeof(char *) * 2);
|
||||||
file_list[0] = NULL;
|
|
||||||
} else {
|
|
||||||
file_list = xmalloc(sizeof(char *) * 3);
|
|
||||||
file_list[0] = xstrdup(filename);
|
file_list[0] = xstrdup(filename);
|
||||||
file_list[1] = NULL;
|
file_list[1] = NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user