Fix exclude/include problem
authorGlenn L McGrath <bug1@ihug.co.nz>
Sat, 19 Oct 2002 06:19:22 +0000 (06:19 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Sat, 19 Oct 2002 06:19:22 +0000 (06:19 -0000)
archival/libunarchive/Makefile.in
archival/libunarchive/filter_accept_list.c
archival/libunarchive/filter_accept_reject_list.c
archival/libunarchive/get_header_tar.c
archival/tar.c
include/unarchive.h

index e2ac546abf3a30d69b2b0c7c1f7b9a838f2b28a0..e559cb40e7d0c07b236694b7207db9b1ec56896a 100644 (file)
@@ -48,6 +48,7 @@ LIBUNARCHIVE-y:= \
        init_handle.o \
        seek_sub_file.o \
        unpack_ar_archive.o \
+       find_list_entry.o
 
 LIBUNARCHIVE-$(CONFIG_DPKG) += 
 LIBUNARCHIVE-$(CONFIG_DPKG_DEB) += 
index 9f92e644003a871cd1b5ef473f8cc639fc833dc3..2b023ec705765f8f341fc542c17aea64bfeaeb79 100644 (file)
@@ -1,24 +1,15 @@
 #include <fnmatch.h>
 #include <stdlib.h>
 #include "unarchive.h"
+
 /*
  * Accept names that are in the accept list
  */
 extern char filter_accept_list(const llist_t *accept_list, const llist_t *reject_list, const char *key)
 {
-       llist_t *accept_old;
-
-       while (accept_list) {
-               if (fnmatch(accept_list->data, key, 0) == 0) {
-                       /* Remove entry from list */
-                       accept_old->link = accept_list->link;
-                       free(accept_list->data);
-                       free(accept_list);
-                       accept_list = accept_old;
-                       return(EXIT_SUCCESS);
-               }
-               accept_old = accept_list;
-               accept_list = accept_list->link;
+       if (find_list_entry(accept_list, key)) {
+               return(EXIT_SUCCESS);
+       } else {
+               return(EXIT_FAILURE);
        }
-       return(EXIT_FAILURE);
 }
index c893dfcfc1516ea4a1b094539bad5244e99b1632..21fecf12055092e6b026a2acd7ca35dfb928045b 100644 (file)
@@ -2,33 +2,24 @@
 #include <stdlib.h>
 #include "unarchive.h"
 
-static char check_list(const llist_t *list, const char *filename)
-{
-       if (list) {
-               while (list) {
-                       if (fnmatch(list->data, filename, 0) == 0) {
-                               return(EXIT_SUCCESS);
-                       }
-                       list = list->link;
-               }
-       }
-       return(EXIT_FAILURE);
-}
-
 /*
  * Accept names that are in the accept list
  */
 extern char filter_accept_reject_list(const llist_t *accept_list, const llist_t *reject_list, const char *key)
 {
+       const llist_t *accept_entry = find_list_entry(accept_list, key);
+       const llist_t *reject_entry = find_list_entry(reject_list, key);
+
        /* Fail if an accept list was specified and the key wasnt in there */
-       if ((accept_list) && (check_list(accept_list, key) == EXIT_FAILURE)) {
+       if (accept_list && (accept_entry == NULL)) {
                return(EXIT_FAILURE);
        }
 
        /* If the key is in a reject list fail */
-       if (check_list(reject_list, key) == EXIT_FAILURE) {
+       if (reject_entry) {
                return(EXIT_FAILURE);
        }
 
+       /* Accepted */
        return(EXIT_SUCCESS);
 }
index bb0affeb3c5677f1066a51397adede93a391e858..e87eb77b8149149775f2b952f13bfaa5d2fca0c9 100644 (file)
@@ -47,6 +47,7 @@ extern char get_header_tar(archive_handle_t *archive_handle)
        } tar;
        long sum = 0;
        long i;
+       char *tmp;
 
        /* Align header */
        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)
        } else {
                file_header->name = concat_path_file(tar.formated.prefix, tar.formated.name);
        }
+       tmp = last_char_is(archive_handle->file_header->name, '/');
+       if (tmp) {
+               *tmp = '\0';
+       }
+
        file_header->mode = strtol(tar.formated.mode, NULL, 8);
        file_header->uid = strtol(tar.formated.uid, NULL, 8);
        file_header->gid = strtol(tar.formated.gid, NULL, 8);
@@ -159,6 +165,7 @@ extern char get_header_tar(archive_handle_t *archive_handle)
                archive_handle->action_header(archive_handle->file_header);
                archive_handle->flags |= ARCHIVE_EXTRACT_QUIET;
                archive_handle->action_data(archive_handle);
+               archive_handle->passed = add_to_list(archive_handle->passed, archive_handle->file_header->name);
        } else {
                data_skip(archive_handle);                      
        }
index df110a1494c0ce043211ec6026e8e292201b8bbe..d8889ae19775d22b5d07a3922481eb22bcef56e3 100644 (file)
@@ -586,14 +586,10 @@ static inline int writeTarFile(const char *tarName, const int verboseFlag,
 static const llist_t *append_file_list_to_list(const char *filename, const llist_t *list)
 {
        FILE *src_stream = xfopen(filename, "r");
-       while(1) {
-               char *line = get_line_from_file(src_stream);
-               if (line == NULL) {
-                       break;
-               }
+       char *line;
+       while((line = get_line_from_file(src_stream)) != NULL) {
                chomp(line);
                list = add_to_list(list, line);
-               free(line);
        }
        fclose(src_stream);
 
@@ -715,14 +711,10 @@ int tar_main(int argc, char **argv)
                tar_handle->accept = add_to_list(tar_handle->accept, argv[optind]);
                optind++;
 
-#ifdef CONFIG_FEATURE_TAR_EXCLUDE
-               if (tar_handle->reject) {
-                       printf("Reject list\n");
-                       tar_handle->filter = filter_accept_reject_list;
-               } else
-#endif /* CONFIG_FEATURE_TAR_EXCLUDE */
+       }
 
-                       tar_handle->filter = filter_accept_list;
+       if ((tar_handle->accept) || (tar_handle->reject)) {
+               tar_handle->filter = filter_accept_reject_list;
        }
 
        if ((base_dir) && (chdir(base_dir))) {
@@ -761,13 +753,18 @@ int tar_main(int argc, char **argv)
 #endif /* CONFIG_FEATURE_TAR_CREATE */
 
                        while (get_header_tar(tar_handle) == EXIT_SUCCESS);
-       }
 
-       /* Skip through list */
-       while (tar_handle->accept) {
-               error_msg_and_die("%s: Not found in archive\n", tar_handle->accept->data);
-               tar_handle->accept = tar_handle->accept->link;
+               /* Ckeck that every file that should have been extracted was */
+               while (tar_handle->accept) {
+                       if (find_list_entry(tar_handle->reject, tar_handle->accept->data) == NULL) {
+                               if (find_list_entry(tar_handle->passed, tar_handle->accept->data) == NULL) {
+                                       error_msg_and_die("%s: Not found in archive\n", tar_handle->accept->data);
+                               }
+                       }
+                       tar_handle->accept = tar_handle->accept->link;
+               }
        }
+
 #ifdef CONFIG_FEATURE_CLEAN_UP
        if (tar_handle->src_fd != fileno(stdin)) {
                close(tar_handle->src_fd);
index 023c3e8aabb8274aa6f032adaa69c3238dfbc8de..956c74fb860ab7850b57a46225f9e214c34f4f3b 100644 (file)
@@ -36,6 +36,7 @@ typedef struct archive_handle_s {
        char (*filter)(const llist_t *, const llist_t *, const char *);
        const llist_t *accept;
        const llist_t *reject;
+       const llist_t *passed;  /* List of files that have successfully been worked on */
 
        /* Contains the processed header entry */
        file_header_t *file_header;
@@ -89,5 +90,5 @@ extern void seek_sub_file(int src_fd, unsigned int amount);
 extern const unsigned short data_align(const int src_fd, const unsigned int offset, const unsigned short align_to);
 extern const llist_t *add_to_list(const llist_t *old_head, const char *new_item);
 extern int copy_file_chunk_fd(int src_fd, int dst_fd, unsigned long long chunksize);
-
+extern const llist_t *find_list_entry(const llist_t *list, const char *filename);
 #endif