diff options
| author | Glenn L McGrath <bug1@ihug.co.nz> | 2002-10-19 06:19:22 +0000 |
|---|---|---|
| committer | Glenn L McGrath <bug1@ihug.co.nz> | 2002-10-19 06:19:22 +0000 |
| commit | c5c1a8a112ebae29862a902e6e511b392c59da74 (patch) | |
| tree | 88df433818b25262966b84fa81aecde8b75c8ed1 | |
| parent | 05fa661123d90b990c146ef6d79da82d798ccd6f (diff) | |
| download | busybox-w32-c5c1a8a112ebae29862a902e6e511b392c59da74.tar.gz busybox-w32-c5c1a8a112ebae29862a902e6e511b392c59da74.tar.bz2 busybox-w32-c5c1a8a112ebae29862a902e6e511b392c59da74.zip | |
Fix exclude/include problem
| -rw-r--r-- | archival/libunarchive/Makefile.in | 1 | ||||
| -rw-r--r-- | archival/libunarchive/filter_accept_list.c | 19 | ||||
| -rw-r--r-- | archival/libunarchive/filter_accept_reject_list.c | 21 | ||||
| -rw-r--r-- | archival/libunarchive/get_header_tar.c | 7 | ||||
| -rw-r--r-- | archival/tar.c | 33 | ||||
| -rw-r--r-- | include/unarchive.h | 3 |
6 files changed, 36 insertions, 48 deletions
diff --git a/archival/libunarchive/Makefile.in b/archival/libunarchive/Makefile.in index e2ac546ab..e559cb40e 100644 --- a/archival/libunarchive/Makefile.in +++ b/archival/libunarchive/Makefile.in | |||
| @@ -48,6 +48,7 @@ LIBUNARCHIVE-y:= \ | |||
| 48 | init_handle.o \ | 48 | init_handle.o \ |
| 49 | seek_sub_file.o \ | 49 | seek_sub_file.o \ |
| 50 | unpack_ar_archive.o \ | 50 | unpack_ar_archive.o \ |
| 51 | find_list_entry.o | ||
| 51 | 52 | ||
| 52 | LIBUNARCHIVE-$(CONFIG_DPKG) += | 53 | LIBUNARCHIVE-$(CONFIG_DPKG) += |
| 53 | LIBUNARCHIVE-$(CONFIG_DPKG_DEB) += | 54 | LIBUNARCHIVE-$(CONFIG_DPKG_DEB) += |
diff --git a/archival/libunarchive/filter_accept_list.c b/archival/libunarchive/filter_accept_list.c index 9f92e6440..2b023ec70 100644 --- a/archival/libunarchive/filter_accept_list.c +++ b/archival/libunarchive/filter_accept_list.c | |||
| @@ -1,24 +1,15 @@ | |||
| 1 | #include <fnmatch.h> | 1 | #include <fnmatch.h> |
| 2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
| 3 | #include "unarchive.h" | 3 | #include "unarchive.h" |
| 4 | |||
| 4 | /* | 5 | /* |
| 5 | * Accept names that are in the accept list | 6 | * Accept names that are in the accept list |
| 6 | */ | 7 | */ |
| 7 | extern char filter_accept_list(const llist_t *accept_list, const llist_t *reject_list, const char *key) | 8 | extern char filter_accept_list(const llist_t *accept_list, const llist_t *reject_list, const char *key) |
| 8 | { | 9 | { |
| 9 | llist_t *accept_old; | 10 | if (find_list_entry(accept_list, key)) { |
| 10 | 11 | return(EXIT_SUCCESS); | |
| 11 | while (accept_list) { | 12 | } else { |
| 12 | if (fnmatch(accept_list->data, key, 0) == 0) { | 13 | return(EXIT_FAILURE); |
| 13 | /* Remove entry from list */ | ||
| 14 | accept_old->link = accept_list->link; | ||
| 15 | free(accept_list->data); | ||
| 16 | free(accept_list); | ||
| 17 | accept_list = accept_old; | ||
| 18 | return(EXIT_SUCCESS); | ||
| 19 | } | ||
| 20 | accept_old = accept_list; | ||
| 21 | accept_list = accept_list->link; | ||
| 22 | } | 14 | } |
| 23 | return(EXIT_FAILURE); | ||
| 24 | } | 15 | } |
diff --git a/archival/libunarchive/filter_accept_reject_list.c b/archival/libunarchive/filter_accept_reject_list.c index c893dfcfc..21fecf120 100644 --- a/archival/libunarchive/filter_accept_reject_list.c +++ b/archival/libunarchive/filter_accept_reject_list.c | |||
| @@ -2,33 +2,24 @@ | |||
| 2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
| 3 | #include "unarchive.h" | 3 | #include "unarchive.h" |
| 4 | 4 | ||
| 5 | static char check_list(const llist_t *list, const char *filename) | ||
| 6 | { | ||
| 7 | if (list) { | ||
| 8 | while (list) { | ||
| 9 | if (fnmatch(list->data, filename, 0) == 0) { | ||
| 10 | return(EXIT_SUCCESS); | ||
| 11 | } | ||
| 12 | list = list->link; | ||
| 13 | } | ||
| 14 | } | ||
| 15 | return(EXIT_FAILURE); | ||
| 16 | } | ||
| 17 | |||
| 18 | /* | 5 | /* |
| 19 | * Accept names that are in the accept list | 6 | * Accept names that are in the accept list |
| 20 | */ | 7 | */ |
| 21 | extern char filter_accept_reject_list(const llist_t *accept_list, const llist_t *reject_list, const char *key) | 8 | extern char filter_accept_reject_list(const llist_t *accept_list, const llist_t *reject_list, const char *key) |
| 22 | { | 9 | { |
| 10 | const llist_t *accept_entry = find_list_entry(accept_list, key); | ||
| 11 | const llist_t *reject_entry = find_list_entry(reject_list, key); | ||
| 12 | |||
| 23 | /* Fail if an accept list was specified and the key wasnt in there */ | 13 | /* Fail if an accept list was specified and the key wasnt in there */ |
| 24 | if ((accept_list) && (check_list(accept_list, key) == EXIT_FAILURE)) { | 14 | if (accept_list && (accept_entry == NULL)) { |
| 25 | return(EXIT_FAILURE); | 15 | return(EXIT_FAILURE); |
| 26 | } | 16 | } |
| 27 | 17 | ||
| 28 | /* If the key is in a reject list fail */ | 18 | /* If the key is in a reject list fail */ |
| 29 | if (check_list(reject_list, key) == EXIT_FAILURE) { | 19 | if (reject_entry) { |
| 30 | return(EXIT_FAILURE); | 20 | return(EXIT_FAILURE); |
| 31 | } | 21 | } |
| 32 | 22 | ||
| 23 | /* Accepted */ | ||
| 33 | return(EXIT_SUCCESS); | 24 | return(EXIT_SUCCESS); |
| 34 | } | 25 | } |
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index bb0affeb3..e87eb77b8 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c | |||
| @@ -47,6 +47,7 @@ extern char get_header_tar(archive_handle_t *archive_handle) | |||
| 47 | } tar; | 47 | } tar; |
| 48 | long sum = 0; | 48 | long sum = 0; |
| 49 | long i; | 49 | long i; |
| 50 | char *tmp; | ||
| 50 | 51 | ||
| 51 | /* Align header */ | 52 | /* Align header */ |
| 52 | archive_handle->offset += data_align(archive_handle->src_fd, archive_handle->offset, 512); | 53 | archive_handle->offset += data_align(archive_handle->src_fd, archive_handle->offset, 512); |
| @@ -91,6 +92,11 @@ extern char get_header_tar(archive_handle_t *archive_handle) | |||
| 91 | } else { | 92 | } else { |
| 92 | file_header->name = concat_path_file(tar.formated.prefix, tar.formated.name); | 93 | file_header->name = concat_path_file(tar.formated.prefix, tar.formated.name); |
| 93 | } | 94 | } |
| 95 | tmp = last_char_is(archive_handle->file_header->name, '/'); | ||
| 96 | if (tmp) { | ||
| 97 | *tmp = '\0'; | ||
| 98 | } | ||
| 99 | |||
| 94 | file_header->mode = strtol(tar.formated.mode, NULL, 8); | 100 | file_header->mode = strtol(tar.formated.mode, NULL, 8); |
| 95 | file_header->uid = strtol(tar.formated.uid, NULL, 8); | 101 | file_header->uid = strtol(tar.formated.uid, NULL, 8); |
| 96 | file_header->gid = strtol(tar.formated.gid, NULL, 8); | 102 | file_header->gid = strtol(tar.formated.gid, NULL, 8); |
| @@ -159,6 +165,7 @@ extern char get_header_tar(archive_handle_t *archive_handle) | |||
| 159 | archive_handle->action_header(archive_handle->file_header); | 165 | archive_handle->action_header(archive_handle->file_header); |
| 160 | archive_handle->flags |= ARCHIVE_EXTRACT_QUIET; | 166 | archive_handle->flags |= ARCHIVE_EXTRACT_QUIET; |
| 161 | archive_handle->action_data(archive_handle); | 167 | archive_handle->action_data(archive_handle); |
| 168 | archive_handle->passed = add_to_list(archive_handle->passed, archive_handle->file_header->name); | ||
| 162 | } else { | 169 | } else { |
| 163 | data_skip(archive_handle); | 170 | data_skip(archive_handle); |
| 164 | } | 171 | } |
diff --git a/archival/tar.c b/archival/tar.c index df110a149..d8889ae19 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
| @@ -586,14 +586,10 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag, | |||
| 586 | static const llist_t *append_file_list_to_list(const char *filename, const llist_t *list) | 586 | static const llist_t *append_file_list_to_list(const char *filename, const llist_t *list) |
| 587 | { | 587 | { |
| 588 | FILE *src_stream = xfopen(filename, "r"); | 588 | FILE *src_stream = xfopen(filename, "r"); |
| 589 | while(1) { | 589 | char *line; |
| 590 | char *line = get_line_from_file(src_stream); | 590 | while((line = get_line_from_file(src_stream)) != NULL) { |
| 591 | if (line == NULL) { | ||
| 592 | break; | ||
| 593 | } | ||
| 594 | chomp(line); | 591 | chomp(line); |
| 595 | list = add_to_list(list, line); | 592 | list = add_to_list(list, line); |
| 596 | free(line); | ||
| 597 | } | 593 | } |
| 598 | fclose(src_stream); | 594 | fclose(src_stream); |
| 599 | 595 | ||
| @@ -715,14 +711,10 @@ int tar_main(int argc, char **argv) | |||
| 715 | tar_handle->accept = add_to_list(tar_handle->accept, argv[optind]); | 711 | tar_handle->accept = add_to_list(tar_handle->accept, argv[optind]); |
| 716 | optind++; | 712 | optind++; |
| 717 | 713 | ||
| 718 | #ifdef CONFIG_FEATURE_TAR_EXCLUDE | 714 | } |
| 719 | if (tar_handle->reject) { | ||
| 720 | printf("Reject list\n"); | ||
| 721 | tar_handle->filter = filter_accept_reject_list; | ||
| 722 | } else | ||
| 723 | #endif /* CONFIG_FEATURE_TAR_EXCLUDE */ | ||
| 724 | 715 | ||
| 725 | tar_handle->filter = filter_accept_list; | 716 | if ((tar_handle->accept) || (tar_handle->reject)) { |
| 717 | tar_handle->filter = filter_accept_reject_list; | ||
| 726 | } | 718 | } |
| 727 | 719 | ||
| 728 | if ((base_dir) && (chdir(base_dir))) { | 720 | if ((base_dir) && (chdir(base_dir))) { |
| @@ -761,13 +753,18 @@ int tar_main(int argc, char **argv) | |||
| 761 | #endif /* CONFIG_FEATURE_TAR_CREATE */ | 753 | #endif /* CONFIG_FEATURE_TAR_CREATE */ |
| 762 | 754 | ||
| 763 | while (get_header_tar(tar_handle) == EXIT_SUCCESS); | 755 | while (get_header_tar(tar_handle) == EXIT_SUCCESS); |
| 764 | } | ||
| 765 | 756 | ||
| 766 | /* Skip through list */ | 757 | /* Ckeck that every file that should have been extracted was */ |
| 767 | while (tar_handle->accept) { | 758 | while (tar_handle->accept) { |
| 768 | error_msg_and_die("%s: Not found in archive\n", tar_handle->accept->data); | 759 | if (find_list_entry(tar_handle->reject, tar_handle->accept->data) == NULL) { |
| 769 | tar_handle->accept = tar_handle->accept->link; | 760 | if (find_list_entry(tar_handle->passed, tar_handle->accept->data) == NULL) { |
| 761 | error_msg_and_die("%s: Not found in archive\n", tar_handle->accept->data); | ||
| 762 | } | ||
| 763 | } | ||
| 764 | tar_handle->accept = tar_handle->accept->link; | ||
| 765 | } | ||
| 770 | } | 766 | } |
| 767 | |||
| 771 | #ifdef CONFIG_FEATURE_CLEAN_UP | 768 | #ifdef CONFIG_FEATURE_CLEAN_UP |
| 772 | if (tar_handle->src_fd != fileno(stdin)) { | 769 | if (tar_handle->src_fd != fileno(stdin)) { |
| 773 | close(tar_handle->src_fd); | 770 | close(tar_handle->src_fd); |
diff --git a/include/unarchive.h b/include/unarchive.h index 023c3e8aa..956c74fb8 100644 --- a/include/unarchive.h +++ b/include/unarchive.h | |||
| @@ -36,6 +36,7 @@ typedef struct archive_handle_s { | |||
| 36 | char (*filter)(const llist_t *, const llist_t *, const char *); | 36 | char (*filter)(const llist_t *, const llist_t *, const char *); |
| 37 | const llist_t *accept; | 37 | const llist_t *accept; |
| 38 | const llist_t *reject; | 38 | const llist_t *reject; |
| 39 | const llist_t *passed; /* List of files that have successfully been worked on */ | ||
| 39 | 40 | ||
| 40 | /* Contains the processed header entry */ | 41 | /* Contains the processed header entry */ |
| 41 | file_header_t *file_header; | 42 | file_header_t *file_header; |
| @@ -89,5 +90,5 @@ extern void seek_sub_file(int src_fd, unsigned int amount); | |||
| 89 | extern const unsigned short data_align(const int src_fd, const unsigned int offset, const unsigned short align_to); | 90 | extern const unsigned short data_align(const int src_fd, const unsigned int offset, const unsigned short align_to); |
| 90 | extern const llist_t *add_to_list(const llist_t *old_head, const char *new_item); | 91 | extern const llist_t *add_to_list(const llist_t *old_head, const char *new_item); |
| 91 | extern int copy_file_chunk_fd(int src_fd, int dst_fd, unsigned long long chunksize); | 92 | extern int copy_file_chunk_fd(int src_fd, int dst_fd, unsigned long long chunksize); |
| 92 | 93 | extern const llist_t *find_list_entry(const llist_t *list, const char *filename); | |
| 93 | #endif | 94 | #endif |
