From: Tollef Fog Heen Date: Sun, 20 Jan 2008 20:46:19 +0000 (+0100) Subject: Move filtering function to filters.c X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=832c1b80ffece7c20e026d7f105eda3aa696c830;p=dpkg Move filtering function to filters.c Move checking for filtering to filters.c and add appropriate #includes to filters.h and archives.c. --- diff --git a/src/archives.c b/src/archives.c index 90a74e4a..f81ccbd2 100644 --- a/src/archives.c +++ b/src/archives.c @@ -407,44 +407,7 @@ int tarobject(struct TarInfo *ti) { nifd->namenode->divert && nifd->namenode->divert->useinstead ? nifd->namenode->divert->useinstead->name : ""); - if (filters) { - int remove = 0; - 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 (fnmatch(f->filterstring, &ti->Name[1], 0) == 0) { - 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); - - } - } - } - - 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) { + if (filter_should_skip(ti) == 1) { struct filenamenode *fnn = findnamenode(ti->Name, 0); fnn->flags &= ~fnnf_new_inarchive; obstack_free(&tar_obs, nifd); @@ -461,7 +424,6 @@ int tarobject(struct TarInfo *ti) { if (r > 0) r= safe_read(tc->backendpipe,databuf,TARBLKSZ - r); } return 0; - } } if (nifd->namenode->divert && nifd->namenode->divert->camefrom) { diff --git a/src/filters.c b/src/filters.c index 702a70e9..ae69dbcf 100644 --- a/src/filters.c +++ b/src/filters.c @@ -28,10 +28,12 @@ #include #include #include +#include #include #include "filters.h" +#include "main.h" struct filterlist *filters = NULL; @@ -120,3 +122,44 @@ void loadfilters(void) { } closedir(dir); } + +int filter_should_skip(struct TarInfo *ti) { + int remove = 0; + if (filters) { + 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 (fnmatch(f->filterstring, &ti->Name[1], 0) == 0) { + if (f->positive == 0) { + remove = 1; + debug(dbg_eachfile, "do_filter removing %s", ti->Name); + } else { + remove = 0; + debug(dbg_eachfile, "do_filter including %s", ti->Name); + } + } + } + + 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); + } + } + } + } + return remove; +} diff --git a/src/filters.h b/src/filters.h index d4dba5c2..c1de3087 100644 --- a/src/filters.h +++ b/src/filters.h @@ -19,8 +19,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "tarfn.h" + void loadfilter(char *fn); void loadfilters(void); +int filter_should_skip(struct TarInfo *ti); struct filterlist { int positive;