[patch] Touching tar with tweezers...
Rob Landley
rob at landley.net
Tue Aug 30 04:40:29 UTC 2005
Code removal. Always fun.
Does the attached "svn diff" look sane? It makes filter_accept_reject_list() do all the
filtering, which means we can shoot archival/libunarchive/filter_accept_all.c and
filter_accept_list.c in the head. (This patch doesn't delete them because
that's a svn action, but with it applied those two files are not used.)
Along the way, I cleaned up filter_accept_reject_list() itself, and untangled
the return values. Returning FALSE to indicate success and TRUE to indicate
failure is just wrong, but since EXIT_SUCCESS is 0 and EXIT_FAILURE
is nonzero (because they're program exit codes, not truth values), that's
exactly what it was doing...
I left filter_accept_list_reassign() alone because I don't know what to do
with it (it has nothing to do with filtering), but it's not currently
connected up to anything. As a result, this patch breaks dpkg (and dpkg_deb),
or at least the dynamic filetype detection bit. The references were just
commented out with no attempt to make that actually work because I neither use
it nor understand it. (Anybody else want to take a swing at this?)
This is probably the start of more widespread cleanups to the archive stuff
because, well, I made the mistake of reading some of it...
Rob
Index: archival/dpkg_deb.c
===================================================================
--- archival/dpkg_deb.c (revision 11284)
+++ archival/dpkg_deb.c (working copy)
@@ -44,7 +44,7 @@
/* Setup an ar archive handle that refers to the gzip sub archive */
ar_archive = init_handle();
ar_archive->sub_archive = tar_archive;
- ar_archive->filter = filter_accept_list_reassign;
+ // ar_archive->filter = filter_accept_list_reassign;
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
ar_archive->accept = llist_add_to(NULL, "data.tar.gz");
@@ -77,7 +77,7 @@
* specific field to print */
ar_archive->accept = control_tar_llist;
tar_archive->accept = llist_add_to(NULL, "./control");;
- tar_archive->filter = filter_accept_list;
+ // tar_archive->filter = filter_accept_list;
tar_archive->action_data = data_extract_to_stdout;
}
if (opt & DPKG_DEB_OPT_EXTRACT) {
Index: archival/ar.c
===================================================================
--- archival/ar.c (revision 11284)
+++ archival/ar.c (working copy)
@@ -99,7 +99,6 @@
archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY);
while (optind < argc) {
- archive_handle->filter = filter_accept_list;
archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind++]);
}
Index: archival/dpkg.c
===================================================================
--- archival/dpkg.c (revision 11284)
+++ archival/dpkg.c (working copy)
@@ -1466,7 +1466,7 @@
/* Setup an ar archive handle that refers to the gzip sub archive */
ar_handle = init_handle();
- ar_handle->filter = filter_accept_list_reassign;
+ // ar_handle->filter = filter_accept_list_reassign;
ar_handle->src_fd = bb_xopen(filename, O_RDONLY);
return(ar_handle);
@@ -1520,7 +1520,7 @@
{
ar_handle->sub_archive->action_data = data_extract_to_buffer;
ar_handle->sub_archive->accept = myaccept;
- ar_handle->sub_archive->filter = filter_accept_list;
+ // ar_handle->sub_archive->filter = filter_accept_list;
unpack_ar_archive(ar_handle);
close(ar_handle->src_fd);
@@ -1577,7 +1577,7 @@
i++;
}
archive_handle->sub_archive->accept = accept_list;
- archive_handle->sub_archive->filter = filter_accept_list;
+ // archive_handle->sub_archive->filter = filter_accept_list;
archive_handle->sub_archive->action_data = data_extract_all_prefix;
archive_handle->sub_archive->buffer = info_prefix;
archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
Index: archival/tar.c
===================================================================
--- archival/tar.c (revision 11284)
+++ archival/tar.c (working copy)
@@ -802,10 +802,6 @@
optind++;
}
- if ((tar_handle->accept) || (tar_handle->reject)) {
- tar_handle->filter = filter_accept_reject_list;
- }
-
/* Open the tar file */
{
FILE *tar_stream;
Index: archival/libunarchive/Makefile.in
===================================================================
--- archival/libunarchive/Makefile.in (revision 11284)
+++ archival/libunarchive/Makefile.in (working copy)
@@ -30,8 +30,6 @@
data_extract_to_stdout.o \
data_extract_to_buffer.o \
\
- filter_accept_all.o \
- filter_accept_list.o \
filter_accept_reject_list.o \
\
header_skip.o \
Index: archival/libunarchive/get_header_cpio.c
===================================================================
--- archival/libunarchive/get_header_cpio.c (revision 11284)
+++ archival/libunarchive/get_header_cpio.c (working copy)
@@ -146,7 +146,7 @@
}
file_header->device = makedev(major, minor);
- if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
+ if (filter_accept_reject_list(archive_handle)) {
archive_handle->action_data(archive_handle);
archive_handle->action_header(archive_handle->file_header);
} else {
Index: archival/libunarchive/get_header_ar.c
===================================================================
--- archival/libunarchive/get_header_ar.c (revision 11284)
+++ archival/libunarchive/get_header_ar.c (working copy)
@@ -107,7 +107,7 @@
typed->name[strcspn(typed->name, " /")] = '\0';
- if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
+ if (filter_accept_reject_list(archive_handle)) {
archive_handle->action_header(typed);
if (archive_handle->sub_archive) {
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS);
Index: archival/libunarchive/init_handle.c
===================================================================
--- archival/libunarchive/init_handle.c (revision 11284)
+++ archival/libunarchive/init_handle.c (working copy)
@@ -29,7 +29,6 @@
archive_handle->file_header = xmalloc(sizeof(file_header_t));
archive_handle->action_header = header_skip;
archive_handle->action_data = data_skip;
- archive_handle->filter = filter_accept_all;
archive_handle->seek = seek_by_jump;
return(archive_handle);
Index: archival/libunarchive/get_header_tar.c
===================================================================
--- archival/libunarchive/get_header_tar.c (revision 11284)
+++ archival/libunarchive/get_header_tar.c (working copy)
@@ -209,7 +209,7 @@
}
}
- if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
+ if (filter_accept_reject_list(archive_handle)) {
archive_handle->action_header(archive_handle->file_header);
archive_handle->flags |= ARCHIVE_EXTRACT_QUIET;
archive_handle->action_data(archive_handle);
Index: archival/libunarchive/filter_accept_reject_list.c
===================================================================
--- archival/libunarchive/filter_accept_reject_list.c (revision 11284)
+++ archival/libunarchive/filter_accept_reject_list.c (working copy)
@@ -24,22 +24,17 @@
/*
* Accept names that are in the accept list and not in the reject list
*/
-extern char filter_accept_reject_list(archive_handle_t *archive_handle)
+extern char filter_accept_reject_list(archive_handle_t *ah)
{
- const char *key = archive_handle->file_header->name;
- const llist_t *accept_entry = find_list_entry(archive_handle->accept, key);
- const llist_t *reject_entry = find_list_entry(archive_handle->reject, key);
+ const char *key = ah->file_header->name;
/* If the key is in a reject list fail */
- if (reject_entry) {
- return(EXIT_FAILURE);
- }
+ if (find_list_entry(ah->reject, key)) return 0;
/* Fail if an accept list was specified and the key wasnt in there */
- if (archive_handle->accept && (accept_entry == NULL)) {
- return(EXIT_FAILURE);
- }
+ if (ah->accept && !find_list_entry(ah->accept, key))
+ return 0;
/* Accepted */
- return(EXIT_SUCCESS);
+ return 1;
}
Index: archival/cpio.c
===================================================================
--- archival/cpio.c (revision 11284)
+++ archival/cpio.c (working copy)
@@ -88,7 +88,6 @@
}
while (optind < argc) {
- archive_handle->filter = filter_accept_list;
archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind]);
optind++;
}
Index: include/unarchive.h
===================================================================
--- include/unarchive.h (revision 11284)
+++ include/unarchive.h (working copy)
@@ -24,7 +24,6 @@
typedef struct archive_handle_s {
/* define if the header and data compenent should processed */
- char (*filter)(struct archive_handle_s *);
llist_t *accept;
llist_t *reject;
llist_t *passed; /* List of files that have successfully been worked on */
More information about the busybox
mailing list