}
}
- if (remove) {
+ if (remove && ti->Type == Directory) {
debug(dbg_eachfile,
"tarobject seeing if '%s' needs to be reincluded",
&ti->Name[1]);
for (f = filters; f != NULL; f = f->next) {
- char *pattern;
-
- pattern = m_malloc(strlen(ti->Name) + 1);
- strcpy(pattern, &ti->Name[1]);
- strcat(pattern, "*");
-
- if ((f->positive == 1) &&
- (ti->Type == Directory) &&
- (fnmatch(pattern, f->filterstring, 0) == 0)) {
- remove = 0;
- debug(dbg_eachfile, "tarobject reincluding %s",
- ti->Name);
+ char *pattern, *fs, *t;
+
+ if (f->positive != 1)
+ continue;
+
+ pattern = m_strdup(&ti->Name[1]);
+ t = pattern;
+ fs = f->filterstring;
+
+ while (1) {
+ if (*t == *fs && *t != '\0') {
+ t++;
+ fs++;
+ continue;
+ }
+ if (*t == '\0') {
+ /* End of string, we win! */
+ debug(dbg_eachfile, "do_filter reincluding %s",
+ ti->Name);
+ remove = 0;
+ break;
+ }
+ if (*fs == '?') {
+ fs++;
+ t++;
+ continue;
+ }
+ if (*fs == '*') {
+ char *fs_pc = m_strdup(fs);
+ char *t_pc = m_strdup(t);
+ char *tmp;
+
+ tmp = index(fs_pc, '/');
+ if (tmp != NULL) {
+ *tmp = '\0';
+ }
+
+ tmp = index(t_pc, '/');
+ if (tmp != NULL) {
+ *tmp = '\0';
+ }
+
+ debug(dbg_eachfile, "do_filter fnmatch(%s, %s)",
+ fs_pc, t_pc);
+
+ if (fnmatch(fs_pc, t_pc, FNM_PATHNAME) == 0 &&
+ index(t, '/') == NULL) {
+ debug(dbg_eachfile, "do_filter reincluding %s",
+ ti->Name);
+ remove = 0;
+ }
+
+ free (fs_pc);
+ free (t_pc);
+
+ if (index(t, '/') != NULL) {
+ fs++;
+ t = index(t, '/');
+ debug(dbg_eachfile, "do_filter 2(%s, %s)",
+ fs, t);
+
+ continue;
+ }
+
+ break;
+ }
+ if (*fs != *t) {
+ /* Different, so just break */
+ break;
+ }
}
+
free(pattern);
}
}