From 4bef7b41861f02874bce4ac6ab0c8c2484d41d07 Mon Sep 17 00:00:00 2001 From: Glenn L McGrath Date: Sat, 13 Oct 2001 19:43:46 +0000 Subject: unarchive function changed to support both exclude and include lists, applets that use unarchive changed to match. --- libbb/libbb.h | 4 ++-- libbb/unarchive.c | 35 ++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 19 deletions(-) (limited to 'libbb') 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 { extract_quiet = 2048, extract_exclude_list = 4096 }; -char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_header)(FILE *), - const int extract_function, const char *prefix, char **extract_names); +char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *), + const int extract_function, const char *prefix, char **include_name, char **exclude_name); char *deb_extract(const char *package_filename, FILE *out_stream, const int extract_function, const char *prefix, const char *filename); int 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 #ifdef L_unarchive char *unarchive(FILE *src_stream, FILE *out_stream, file_header_t *(*get_headers)(FILE *), - const int extract_function, const char *prefix, char **extract_names) + const int extract_function, const char *prefix, char **include_name, char **exclude_name) { file_header_t *file_entry; - int extract_flag; + int extract_flag = TRUE; int i; char *buffer = NULL; archive_offset = 0; while ((file_entry = get_headers(src_stream)) != NULL) { - extract_flag = TRUE; - if (extract_names != NULL) { - int found_flag = FALSE; - for(i = 0; extract_names[i] != 0; i++) { - if (fnmatch(extract_names[i], file_entry->name, FNM_LEADING_DIR) == 0) { - found_flag = TRUE; + + if (include_name != NULL) { + extract_flag = FALSE; + for(i = 0; include_name[i] != 0; i++) { + if (fnmatch(include_name[i], file_entry->name, FNM_LEADING_DIR) == 0) { + extract_flag = TRUE; break; } } - if (extract_function & extract_exclude_list) { - if (found_flag == TRUE) { - extract_flag = FALSE; - } - } else { - /* If its not found in the include list dont extract it */ - if (found_flag == FALSE) { + } else { + extract_flag = TRUE; + } + + /* If the file entry is in the exclude list dont extract it */ + if (exclude_name != NULL) { + for(i = 0; exclude_name[i] != 0; i++) { + if (fnmatch(exclude_name[i], file_entry->name, FNM_LEADING_DIR) == 0) { extract_flag = FALSE; + break; } } - } if (extract_flag == TRUE) { @@ -607,7 +608,7 @@ char *deb_extract(const char *package_filename, FILE *out_stream, /* open a stream of decompressed data */ uncompressed_stream = gz_open(deb_stream, &gunzip_pid); archive_offset = 0; - output_buffer = unarchive(uncompressed_stream, out_stream, get_header_tar, extract_function, prefix, file_list); + output_buffer = unarchive(uncompressed_stream, out_stream, get_header_tar, extract_function, prefix, file_list, NULL); } seek_sub_file(deb_stream, ar_header->size); free(ar_header->name); -- cgit v1.2.3