#include "main.h"
static struct filterlist *filters = NULL;
- static struct filterlist **filtertail = &filters;
-
-static void loadfilter(const char *fn) {
- FILE *file;
- char linebuf[1024];
-
- file = fopen(fn, "r");
- if (!file) {
- warningf(_("failed to open filter file `%.255s' for reading"), fn);
- return;
- }
-
- while (fgets(linebuf, sizeof(linebuf), file)) {
- struct filterlist *filter;
-
- filter = m_malloc(sizeof(struct filterlist));
- memset(filter, 0, sizeof(struct filterlist));
-
- if (linebuf[0] == '#' || linebuf[0] == '\n') {
- continue;
- }
-
- if (linebuf[strlen(linebuf) - 1] == '\n')
- linebuf[strlen(linebuf) - 1] = '\0';
-
- if (linebuf[0] == '+') {
- filter->positive = 1;
- } else if (linebuf[0] == '-') {
- filter->positive = 0;
- } else {
- warningf(_("Invalid filter line: `%.255s'"), linebuf);
- free(filter);
- continue;
- }
-
- filter->filterstring = strdup(&linebuf[1]);
- if (!filter->filterstring) {
- ohshite(_("Error allocating memory for filter entry"));
- }
-
- *filtertail = filter;
- filtertail = &filter->next;
- }
-
- if (ferror(file))
- ohshite(_("read error in configuration file `%.255s'"), fn);
-
- if (fclose(file))
- ohshite(_("error closing configuration file `%.255s'"), fn);
+static struct filterlist **filtertail = &filters;
+
+static void
+loadfilter(const char *fn)
+{
+ FILE *file;
+ char linebuf[1024];
+
+ file = fopen(fn, "r");
+ if (!file) {
+ warningf(_("failed to open filter file '%.255s' for reading"),
+ fn);
+ return;
+ }
+
+ while (fgets(linebuf, sizeof(linebuf), file)) {
+ struct filterlist *filter;
+
+ filter = m_malloc(sizeof(struct filterlist));
+ memset(filter, 0, sizeof(struct filterlist));
+
+ if (linebuf[0] == '#' || linebuf[0] == '\n')
+ continue;
+
+ if (linebuf[strlen(linebuf) - 1] == '\n')
+ linebuf[strlen(linebuf) - 1] = '\0';
+
+ if (linebuf[0] == '+')
+ filter->positive = 1;
+ else if (linebuf[0] == '-')
+ filter->positive = 0;
+ else {
+ warningf(_("invalid filter line: '%.255s'"), linebuf);
+ free(filter);
+ continue;
+ }
+
+ filter->filterstring = strdup(&linebuf[1]);
+ if (!filter->filterstring)
+ ohshite(_("error allocating memory for filter entry"));
+
+ *filtertail = filter;
+ filtertail = &filter->next;
+ }
+
+ if (ferror(file))
+ ohshite(_("read error in configuration file '%.255s'"), fn);
+
+ if (fclose(file))
+ ohshite(_("error closing configuration file '%.255s'"), fn);
}
-void loadfilters(void) {
- struct dirent *dent;
- char *dirname = CONFIGDIR "/filters.d";
- DIR *dir = opendir(dirname);
- if (!dir) {
- if (errno == ENOENT)
- return;
- else
- ohshite(_("Error opening filters.d"));
- }
-
- while ((dent = readdir(dir)) != NULL) {
- struct stat statbuf;
- char *file = m_malloc(strlen(dirname) + 1 + strlen(dent->d_name) + 1);
- sprintf(file, "%s/%s", dirname, dent->d_name);
- if (stat(file, &statbuf) != 0) {
- ohshite(_("Error stating file"));
- }
- if (S_ISREG(statbuf.st_mode)) {
- loadfilter(file);
- }
- free(file);
- }
- closedir(dir);
+void
+loadfilters(void)
+{
+ struct dirent *dent;
+ char *dirname = CONFIGDIR "/filters.d";
+ DIR *dir = opendir(dirname);
+
+ if (!dir) {
+ if (errno == ENOENT)
+ return;
+ else
+ ohshite(_("error opening filters.d"));
+ }
+
+ while ((dent = readdir(dir)) != NULL) {
+ struct stat statbuf;
+ char *file = m_malloc(strlen(dirname) + 1 +
+ strlen(dent->d_name) + 1);
+
+ sprintf(file, "%s/%s", dirname, dent->d_name);
+ if (stat(file, &statbuf) != 0)
+ ohshite(_("error stating file '%s'"), file);
+ if (S_ISREG(statbuf.st_mode))
+ loadfilter(file);
+ free(file);
+ }
+ 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);
+static int
+do_filter_should_skip(struct TarInfo *ti)
+{
+ 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, "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 = m_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) {
+ for (f = filters; f != NULL; f = f->next) {
+ char *pattern;
+
+ pattern = m_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;
+
+ return remove;
+}
+
+int
+filter_should_skip(struct TarInfo *ti)
+{
+ if (filters)
+ return do_filter_should_skip(ti);
+ else
+ return 0;
}
+