#include <errno.h>
#include <ctype.h>
#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <unistd.h>
#include <myopt.h>
#include <dpkg.h>
}
}
}
+
+struct filterlist *filters = NULL;
+
+void loadfilter(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;
+
+ 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);
+ }
+
+ filter = malloc(sizeof(struct filterlist));
+ if (!filter) {
+ ohshite(_("Error allocating memory for filter entry"));
+ }
+
+ filter->filterstring = malloc(strlen(linebuf));
+ if (!filter->filterstring) {
+ ohshite(_("Error allocating memory for filter entry"));
+ }
+ strcpy(filter->filterstring, &linebuf[1]);
+ filter->next = filters;
+ filters = filter;
+ }
+
+ if (ferror(file)) ohshite(_("read error in configuration file `%.255s'"), fn);
+ if (fclose(file)) ohshite(_("error closing configuration file `%.255s'"), fn);
+
+}
+
+void loadfilters() {
+ struct dirent *dent;
+ char *dirname = CONFIGDIR "/filters.d";
+ DIR *dir = opendir(dirname);
+ if (!dir) {
+ if (errno == ENOENT) {
+ return NULL;
+ } else {
+ ohshite(_("Error opening filters.d"));
+ }
+ }
+
+ while ((dent = readdir(dir)) != NULL) {
+ struct stat statbuf;
+ char *file = malloc(strlen(dirname) + 1 + strlen(dent->d_name) + 1);
+ if (!file)
+ ohshite(_("Error allocating memory for file"));
+ 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);
+}
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <fnmatch.h>
#include <obstack.h>
#define obstack_chunk_alloc m_malloc
return 1;
}
+extern struct filterlist *filters;
+
int tarobject(struct TarInfo *ti) {
static struct varbuf conffderefn, hardlinkfn, symlinkfn;
const char *usename;
nifd->namenode->divert && nifd->namenode->divert->useinstead
? nifd->namenode->divert->useinstead->name : "<none>");
- if (strcmp(ti->Name, "./usr/share/doc/pkg-config/copyright") == 0) {
- struct filenamenode *fnn = findnamenode(ti->Name, 0);
- fnn->flags &= ~fnnf_new_inarchive;
- obstack_free(&tar_obs, nifd);
- tc->newfilesp= oldnifd;
- *oldnifd = 0;
-
- /* We need to advance the tar file to the next object, so read the
- * file data and set it to oblivion.
- */
- if ((ti->Type == NormalFile0) || (ti->Type == NormalFile1)) {
- char fnamebuf[256];
- fd_null_copy(tc->backendpipe, ti->Size, _("gobble replaced file `%.255s'"),quote_filename(fnamebuf,256,ti->Name));
- r= ti->Size % TARBLKSZ;
- if (r > 0) r= safe_read(tc->backendpipe,databuf,TARBLKSZ - r);
+ if (filters) {
+ int remove = 0;
+ struct filterlist *f = filters;
+ while (f) {
+ 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);
+ }
+ f = f->next;
+ }
+ if (remove) {
+ struct filenamenode *fnn = findnamenode(ti->Name, 0);
+ fnn->flags &= ~fnnf_new_inarchive;
+ obstack_free(&tar_obs, nifd);
+ tc->newfilesp= oldnifd;
+ *oldnifd = 0;
+
+ /* We need to advance the tar file to the next object, so read the
+ * file data and set it to oblivion.
+ */
+ if ((ti->Type == NormalFile0) || (ti->Type == NormalFile1)) {
+ char fnamebuf[256];
+ fd_null_copy(tc->backendpipe, ti->Size, _("gobble replaced file `%.255s'"),quote_filename(fnamebuf,256,ti->Name));
+ r= ti->Size % TARBLKSZ;
+ if (r > 0) r= safe_read(tc->backendpipe,databuf,TARBLKSZ - r);
+ }
+ return 0;
}
-
- return 0;
}
if (nifd->namenode->divert && nifd->namenode->divert->camefrom) {