[SOLVED] why "tar" extraction using "--exclude" is brain-damaged

Robert P. J. Day rpjday at mindspring.com
Wed Apr 12 20:34:50 UTC 2006


  (sometimes, the code in BB really makes me want to claw my eyes
out.)

  in an attempt to figure out why the tar "--exclude" option on
extraction didn't work worth crap, i started poring over the code in
tar.c, specifically the routine i *thought* was responsible for doing
matching:

=========================================================
# ifdef CONFIG_FEATURE_TAR_FROM
static inline int exclude_file(const llist_t *excluded_files, const char *file)
{
    while (excluded_files) {
        if (excluded_files->data[0] == '/') {
            if (fnmatch(excluded_files->data, file,
                        FNM_PATHNAME | FNM_LEADING_DIR) == 0)
                return 1;
        } else {
            const char *p;

            for (p = file; p[0] != '\0'; p++) {
                if ((p == file || p[-1] == '/') && p[0] != '/' &&
                    fnmatch(excluded_files->data, p,
                            FNM_PATHNAME | FNM_LEADING_DIR) == 0)
                    return 1;
            }
        }
        excluded_files = excluded_files->link;
    }

    return 0;
}
... ======================================================

  which, superficially, seemed to be doing the right thing in terms of
using fnmatch() with FNM_LEADING_DIR and so on.  fight with this for a
while, only to suddenly realize this routine has *nothing* to do with
filename matching related to "--exclude".  *that's* done in
libunarchive/find_list_entry.c (a routine which, i should point out,
is *hideously* badly named, like so many others in BB.)

  *that* filename matching uses simply:

	if (fnmatch(list->data, filename, 0) == 0)

replacing it with:

	if (fnmatch(list->data, filename, FNM_LEADING_DIR) == 0)

makes "--exclude" at least start to function a *little* more properly,
but i'll leave it up to the maintainers to decide how to handle this.

  more to the point, why are there two totally separate routines whose
purpose it is to do filename/pattern matching?

rday



More information about the busybox mailing list