aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ar.c2
-rw-r--r--archival/ar.c2
-rw-r--r--archival/cpio.c2
-rw-r--r--archival/tar.c31
-rw-r--r--cpio.c2
-rw-r--r--include/libbb.h4
-rw-r--r--libbb/libbb.h4
-rw-r--r--libbb/unarchive.c35
-rw-r--r--tar.c31
9 files changed, 34 insertions, 79 deletions
diff --git a/ar.c b/ar.c
index 7f3396c8c..e02b2651e 100644
--- a/ar.c
+++ b/ar.c
@@ -84,6 +84,6 @@ extern int ar_main(int argc, char **argv)
84 optind++; 84 optind++;
85 } 85 }
86 86
87 unarchive(src_stream, stdout, &get_header_ar, extract_function, "./", extract_names); 87 unarchive(src_stream, stdout, &get_header_ar, extract_function, "./", extract_names, NULL);
88 return EXIT_SUCCESS; 88 return EXIT_SUCCESS;
89} 89}
diff --git a/archival/ar.c b/archival/ar.c
index 7f3396c8c..e02b2651e 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -84,6 +84,6 @@ extern int ar_main(int argc, char **argv)
84 optind++; 84 optind++;
85 } 85 }
86 86
87 unarchive(src_stream, stdout, &get_header_ar, extract_function, "./", extract_names); 87 unarchive(src_stream, stdout, &get_header_ar, extract_function, "./", extract_names, NULL);
88 return EXIT_SUCCESS; 88 return EXIT_SUCCESS;
89} 89}
diff --git a/archival/cpio.c b/archival/cpio.c
index 7f68715eb..372f9f5b1 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -86,7 +86,7 @@ extern int cpio_main(int argc, char **argv)
86 optind++; 86 optind++;
87 } 87 }
88 88
89 unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names); 89 unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names, NULL);
90 if (oldmask) { 90 if (oldmask) {
91 umask(oldmask); /* Restore umask if we changed it */ 91 umask(oldmask); /* Restore umask if we changed it */
92 } 92 }
diff --git a/archival/tar.c b/archival/tar.c
index 1f8eb4bcb..f7a3da66f 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -580,15 +580,10 @@ int tar_main(int argc, char **argv)
580 untar_extract = 32 580 untar_extract = 32
581 }; 581 };
582 582
583#ifdef BB_FEATURE_TAR_EXCLUDE
584 char **exclude_list = NULL;
585 int exclude_list_count = 0;
586#endif
587
588 FILE *src_stream = NULL; 583 FILE *src_stream = NULL;
589 FILE *uncompressed_stream = NULL; 584 FILE *uncompressed_stream = NULL;
590 char **include_list = NULL; 585 char **include_list = NULL;
591 char **the_real_list = NULL; 586 char **exclude_list = NULL;
592 char *src_filename = NULL; 587 char *src_filename = NULL;
593 char *dst_prefix = NULL; 588 char *dst_prefix = NULL;
594 char *file_list_name = NULL; 589 char *file_list_name = NULL;
@@ -597,6 +592,7 @@ int tar_main(int argc, char **argv)
597 unsigned short untar_funct_required = 0; 592 unsigned short untar_funct_required = 0;
598 unsigned short extract_function = 0; 593 unsigned short extract_function = 0;
599 int include_list_count = 0; 594 int include_list_count = 0;
595 int exclude_list_count = 0;
600 int gunzip_pid; 596 int gunzip_pid;
601 int gz_fd = 0; 597 int gz_fd = 0;
602 598
@@ -691,25 +687,6 @@ int tar_main(int argc, char **argv)
691 optind++; 687 optind++;
692 } 688 }
693 689
694 /* By default the include list is the list we act on */
695 the_real_list = include_list;
696
697#ifdef BB_FEATURE_TAR_EXCLUDE
698 if (exclude_list != NULL) {
699 if (include_list == NULL) {
700 /* the_real_list is an exclude list */
701 extract_function |= extract_exclude_list;
702 the_real_list = exclude_list;
703 } else {
704 /* Both an exclude and include file list was present,
705 * its an exclude from include list only.
706 * Remove excluded files from the include list
707 */
708 the_real_list = list_and_not_list(include_list, exclude_list);
709 }
710 }
711#endif
712
713 if (extract_function & (extract_list | extract_all_to_fs)) { 690 if (extract_function & (extract_list | extract_all_to_fs)) {
714 if (dst_prefix == NULL) { 691 if (dst_prefix == NULL) {
715 dst_prefix = xstrdup("./"); 692 dst_prefix = xstrdup("./");
@@ -730,7 +707,7 @@ int tar_main(int argc, char **argv)
730 uncompressed_stream = src_stream; 707 uncompressed_stream = src_stream;
731 708
732 /* extract or list archive */ 709 /* extract or list archive */
733 unarchive(uncompressed_stream, stdout, &get_header_tar, extract_function, dst_prefix, the_real_list); 710 unarchive(uncompressed_stream, stdout, &get_header_tar, extract_function, dst_prefix, include_list, exclude_list);
734 fclose(uncompressed_stream); 711 fclose(uncompressed_stream);
735 } 712 }
736#ifdef BB_FEATURE_TAR_CREATE 713#ifdef BB_FEATURE_TAR_CREATE
@@ -746,7 +723,7 @@ int tar_main(int argc, char **argv)
746 if (extract_function & extract_verbose_list) { 723 if (extract_function & extract_verbose_list) {
747 verboseFlag = TRUE; 724 verboseFlag = TRUE;
748 } 725 }
749 writeTarFile(src_filename, verboseFlag, &argv[argc - 1], the_real_list); 726 writeTarFile(src_filename, verboseFlag, &argv[argc - 1], include_list);
750 } 727 }
751#endif // BB_FEATURE_TAR_CREATE 728#endif // BB_FEATURE_TAR_CREATE
752 729
diff --git a/cpio.c b/cpio.c
index 7f68715eb..372f9f5b1 100644
--- a/cpio.c
+++ b/cpio.c
@@ -86,7 +86,7 @@ extern int cpio_main(int argc, char **argv)
86 optind++; 86 optind++;
87 } 87 }
88 88
89 unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names); 89 unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names, NULL);
90 if (oldmask) { 90 if (oldmask) {
91 umask(oldmask); /* Restore umask if we changed it */ 91 umask(oldmask); /* Restore umask if we changed it */
92 } 92 }
diff --git a/include/libbb.h b/include/libbb.h
index bbdbc6c86..3ef0278f8 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -245,8 +245,8 @@ enum extract_functions_e {
245 extract_quiet = 2048, 245 extract_quiet = 2048,
246 extract_exclude_list = 4096 246 extract_exclude_list = 4096
247}; 247};
248char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_header)(FILE *), 248char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *),
249 const int extract_function, const char *prefix, char **extract_names); 249 const int extract_function, const char *prefix, char **include_name, char **exclude_name);
250char *deb_extract(const char *package_filename, FILE *out_stream, const int extract_function, 250char *deb_extract(const char *package_filename, FILE *out_stream, const int extract_function,
251 const char *prefix, const char *filename); 251 const char *prefix, const char *filename);
252int read_package_field(const char *package_buffer, char **field_name, char **field_value); 252int read_package_field(const char *package_buffer, char **field_name, char **field_value);
diff --git a/libbb/libbb.h b/libbb/libbb.h
index bbdbc6c86..3ef0278f8 100644
--- a/libbb/libbb.h
+++ b/libbb/libbb.h
@@ -245,8 +245,8 @@ enum extract_functions_e {
245 extract_quiet = 2048, 245 extract_quiet = 2048,
246 extract_exclude_list = 4096 246 extract_exclude_list = 4096
247}; 247};
248char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_header)(FILE *), 248char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *),
249 const int extract_function, const char *prefix, char **extract_names); 249 const int extract_function, const char *prefix, char **include_name, char **exclude_name);
250char *deb_extract(const char *package_filename, FILE *out_stream, const int extract_function, 250char *deb_extract(const char *package_filename, FILE *out_stream, const int extract_function,
251 const char *prefix, const char *filename); 251 const char *prefix, const char *filename);
252int read_package_field(const char *package_buffer, char **field_name, char **field_value); 252int read_package_field(const char *package_buffer, char **field_name, char **field_value);
diff --git a/libbb/unarchive.c b/libbb/unarchive.c
index 37ab67aff..9c599a415 100644
--- a/libbb/unarchive.c
+++ b/libbb/unarchive.c
@@ -230,35 +230,36 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f
230 230
231#ifdef L_unarchive 231#ifdef L_unarchive
232char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *), 232char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *),
233 const int extract_function, const char *prefix, char **extract_names) 233 const int extract_function, const char *prefix, char **include_name, char **exclude_name)
234{ 234{
235 file_header_t *file_entry; 235 file_header_t *file_entry;
236 int extract_flag; 236 int extract_flag = TRUE;
237 int i; 237 int i;
238 char *buffer = NULL; 238 char *buffer = NULL;
239 239
240 archive_offset = 0; 240 archive_offset = 0;
241 while ((file_entry = get_headers(src_stream)) != NULL) { 241 while ((file_entry = get_headers(src_stream)) != NULL) {
242 extract_flag = TRUE; 242
243 if (extract_names != NULL) { 243 if (include_name != NULL) {
244 int found_flag = FALSE; 244 extract_flag = FALSE;
245 for(i = 0; extract_names[i] != 0; i++) { 245 for(i = 0; include_name[i] != 0; i++) {
246 if (fnmatch(extract_names[i], file_entry->name, FNM_LEADING_DIR) == 0) { 246 if (fnmatch(include_name[i], file_entry->name, FNM_LEADING_DIR) == 0) {
247 found_flag = TRUE; 247 extract_flag = TRUE;
248 break; 248 break;
249 } 249 }
250 } 250 }
251 if (extract_function & extract_exclude_list) { 251 } else {
252 if (found_flag == TRUE) { 252 extract_flag = TRUE;
253 extract_flag = FALSE; 253 }
254 } 254
255 } else { 255 /* If the file entry is in the exclude list dont extract it */
256 /* If its not found in the include list dont extract it */ 256 if (exclude_name != NULL) {
257 if (found_flag == FALSE) { 257 for(i = 0; exclude_name[i] != 0; i++) {
258 if (fnmatch(exclude_name[i], file_entry->name, FNM_LEADING_DIR) == 0) {
258 extract_flag = FALSE; 259 extract_flag = FALSE;
260 break;
259 } 261 }
260 } 262 }
261
262 } 263 }
263 264
264 if (extract_flag == TRUE) { 265 if (extract_flag == TRUE) {
@@ -607,7 +608,7 @@ char *deb_extract(const char *package_filename, FILE *out_stream,
607 /* open a stream of decompressed data */ 608 /* open a stream of decompressed data */
608 uncompressed_stream = gz_open(deb_stream, &gunzip_pid); 609 uncompressed_stream = gz_open(deb_stream, &gunzip_pid);
609 archive_offset = 0; 610 archive_offset = 0;
610 output_buffer = unarchive(uncompressed_stream, out_stream, get_header_tar, extract_function, prefix, file_list); 611 output_buffer = unarchive(uncompressed_stream, out_stream, get_header_tar, extract_function, prefix, file_list, NULL);
611 } 612 }
612 seek_sub_file(deb_stream, ar_header->size); 613 seek_sub_file(deb_stream, ar_header->size);
613 free(ar_header->name); 614 free(ar_header->name);
diff --git a/tar.c b/tar.c
index 1f8eb4bcb..f7a3da66f 100644
--- a/tar.c
+++ b/tar.c
@@ -580,15 +580,10 @@ int tar_main(int argc, char **argv)
580 untar_extract = 32 580 untar_extract = 32
581 }; 581 };
582 582
583#ifdef BB_FEATURE_TAR_EXCLUDE
584 char **exclude_list = NULL;
585 int exclude_list_count = 0;
586#endif
587
588 FILE *src_stream = NULL; 583 FILE *src_stream = NULL;
589 FILE *uncompressed_stream = NULL; 584 FILE *uncompressed_stream = NULL;
590 char **include_list = NULL; 585 char **include_list = NULL;
591 char **the_real_list = NULL; 586 char **exclude_list = NULL;
592 char *src_filename = NULL; 587 char *src_filename = NULL;
593 char *dst_prefix = NULL; 588 char *dst_prefix = NULL;
594 char *file_list_name = NULL; 589 char *file_list_name = NULL;
@@ -597,6 +592,7 @@ int tar_main(int argc, char **argv)
597 unsigned short untar_funct_required = 0; 592 unsigned short untar_funct_required = 0;
598 unsigned short extract_function = 0; 593 unsigned short extract_function = 0;
599 int include_list_count = 0; 594 int include_list_count = 0;
595 int exclude_list_count = 0;
600 int gunzip_pid; 596 int gunzip_pid;
601 int gz_fd = 0; 597 int gz_fd = 0;
602 598
@@ -691,25 +687,6 @@ int tar_main(int argc, char **argv)
691 optind++; 687 optind++;
692 } 688 }
693 689
694 /* By default the include list is the list we act on */
695 the_real_list = include_list;
696
697#ifdef BB_FEATURE_TAR_EXCLUDE
698 if (exclude_list != NULL) {
699 if (include_list == NULL) {
700 /* the_real_list is an exclude list */
701 extract_function |= extract_exclude_list;
702 the_real_list = exclude_list;
703 } else {
704 /* Both an exclude and include file list was present,
705 * its an exclude from include list only.
706 * Remove excluded files from the include list
707 */
708 the_real_list = list_and_not_list(include_list, exclude_list);
709 }
710 }
711#endif
712
713 if (extract_function & (extract_list | extract_all_to_fs)) { 690 if (extract_function & (extract_list | extract_all_to_fs)) {
714 if (dst_prefix == NULL) { 691 if (dst_prefix == NULL) {
715 dst_prefix = xstrdup("./"); 692 dst_prefix = xstrdup("./");
@@ -730,7 +707,7 @@ int tar_main(int argc, char **argv)
730 uncompressed_stream = src_stream; 707 uncompressed_stream = src_stream;
731 708
732 /* extract or list archive */ 709 /* extract or list archive */
733 unarchive(uncompressed_stream, stdout, &get_header_tar, extract_function, dst_prefix, the_real_list); 710 unarchive(uncompressed_stream, stdout, &get_header_tar, extract_function, dst_prefix, include_list, exclude_list);
734 fclose(uncompressed_stream); 711 fclose(uncompressed_stream);
735 } 712 }
736#ifdef BB_FEATURE_TAR_CREATE 713#ifdef BB_FEATURE_TAR_CREATE
@@ -746,7 +723,7 @@ int tar_main(int argc, char **argv)
746 if (extract_function & extract_verbose_list) { 723 if (extract_function & extract_verbose_list) {
747 verboseFlag = TRUE; 724 verboseFlag = TRUE;
748 } 725 }
749 writeTarFile(src_filename, verboseFlag, &argv[argc - 1], the_real_list); 726 writeTarFile(src_filename, verboseFlag, &argv[argc - 1], include_list);
750 } 727 }
751#endif // BB_FEATURE_TAR_CREATE 728#endif // BB_FEATURE_TAR_CREATE
752 729