From 79695c34c690e288f6e4d2958a6b587d74d2baa8 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Wed, 26 Dec 2007 10:57:24 +0100 Subject: [PATCH] Handle inclusion properly Make sure we handle the case of a filter similar to: +/usr/share/doc/pkg-config/changelog.Debian.gz -/usr/share/doc/pkg-config* correctly, where /usr/share/doc/pkg-config needs to be reincluded as a file below it will be included. Note that you can end up with empty directories this way if you have a filter like: +/usr/share/doc/pkg-config/NoSuchFileOrDirectory -/usr/share/doc/pkg-config* even though the deb does not ship /usr/share/doc/pkg-config/NoSuchFileOrDirectory. I believe this is not easily fixable without at least a performance hit. --- src/archives.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/archives.c b/src/archives.c index 3e9e4954..a1239402 100644 --- a/src/archives.c +++ b/src/archives.c @@ -408,19 +408,41 @@ int tarobject(struct TarInfo *ti) { if (filters) { int remove = 0; - struct filterlist *f = filters; - while (f) { + struct filterlist *f; + + /* Last match wins */ + for (f = filters; f != NULL; f = f->next) { debug(dbg_eachfile, "tarobject comparing '%s' and '%s'", &ti->Name[1], f->filterstring); - /* if (f->positive && remove == 1) { - remove = 0; - break; - }*/ if (fnmatch(f->filterstring, &ti->Name[1], 0) == 0) { - remove = 1; - debug(dbg_eachfile, "tarobject removing %s", ti->Name); + if (f->positive == 0) { + remove = 1; + debug(dbg_eachfile, "tarobject removing %s", ti->Name); + } else { + remove = 0; + debug(dbg_eachfile, "tarobject including %s", ti->Name); + + } } - f = f->next; } + + if (remove) { + for (f = filters; f != NULL; f = f->next) { + char *pattern; + + pattern = malloc(strlen(ti->Name) + 1); + strcpy(pattern, &ti->Name[1]); + strcat(pattern, "*"); + + debug(dbg_eachfile, "tarobject seeing if '%s' needs to be reincluded", &ti->Name[1]); + if ((f->positive == 1) && + (ti->Type == Directory) && + (fnmatch(pattern, f->filterstring, 0) == 0)) { + remove = 0; + debug(dbg_eachfile, "tarobject reincluding %s", ti->Name); + } + } + } + if (remove) { struct filenamenode *fnn = findnamenode(ti->Name, 0); fnn->flags &= ~fnnf_new_inarchive; -- 2.39.5