int calc_check_exclude( char * filename) { sle_t *an_exclude; if(is_empty_sl(exclude_sl)) return 0; an_exclude=exclude_sl->first; while(an_exclude != NULL) { if(match_tar(an_exclude->name, filename)) { return 1; } an_exclude=an_exclude->next; } return 0; }
static gboolean test_match_tar(void) { gboolean ok = TRUE; struct { char *expr, *str; gboolean should_match; } tests[] = { /* literal, unanchored matching */ { "a", "a", TRUE }, { "abc", "abc", TRUE }, { "abc", "abcd", FALSE }, { "abc", "dabc", FALSE }, { "abc", "/usr/bin/abc", TRUE }, { "*.txt", "foo.txt", TRUE }, { "*.txt", ".txt", TRUE }, { "*.txt", "txt", FALSE }, { "?.txt", "X.txt", TRUE }, { "?.txt", ".txt", FALSE }, { "?.txt", "XY.txt", FALSE }, { "?*.txt", ".txt", FALSE }, { "?*.txt", "a.txt", TRUE }, { "?*.txt", "aa.txt", TRUE }, { "?*.txt", "aaa.txt", TRUE }, { "foo.[tT][xX][tT]", "foo.txt", TRUE }, { "foo.[tT][xX][tT]", "foo.TXt", TRUE }, { "foo.[tT][xX][tT]", "foo.TXT", TRUE }, { "foo.[tT][xX][tT]", "foo.TaT", FALSE }, { "foo.[tT][!yY][tT]", "foo.TXt", TRUE }, { "foo.[tT][!yY][tT]", "foo.TXT", TRUE }, { "foo.[tT][!yY][tT]", "foo.TyT", FALSE }, { "foo\\\\", "foo", FALSE }, { "foo\\\\", "foo\\", TRUE }, { "foo\\\\", "foo\\\\", FALSE }, { "(){}+.^$|", "(){}+.^$|", TRUE }, { "/usr/bin/*", "/usr/bin/tar", TRUE }, { "/usr/bin/*", "/usr/bin/local/tar", TRUE }, /* different from match_glob */ { "/usr/bin/*", "/usr/sbin/tar", FALSE }, { "/usr/bin/*", "/opt/usr/bin/tar", FALSE }, { "/usr?bin", "/usr/bin", FALSE }, { "/usr*bin", "/usr/bin", TRUE }, /* different from match_glob */ /* examples from the amgtar manpage */ { "./temp-files", "./temp-files", TRUE }, { "./temp-files", "./temp-files/foo", TRUE }, { "./temp-files", "./temp-files/foo/bar", TRUE }, { "./temp-files", "./temp-files.bak", FALSE }, { "./temp-files", "./backup/temp-files", FALSE }, { "./temp-files/", "./temp-files", FALSE }, { "./temp-files/", "./temp-files/", TRUE }, { "./temp-files/", "./temp-files/foo", FALSE }, { "./temp-files/", "./temp-files/foo/bar", FALSE }, { "./temp-files/", "./temp-files.bak", FALSE }, { "/temp-files/", "./temp-files", FALSE }, { "/temp-files/", "./temp-files/", FALSE }, { "/temp-files/", "./temp-files/foo", FALSE }, { "/temp-files/", "./temp-files/foo/bar", FALSE }, { "/temp-files/", "./temp-files.bak", FALSE }, { "./temp-files/*", "./temp-files", FALSE }, { "./temp-files/*", "./temp-files/", TRUE }, { "./temp-files/*", "./temp-files/foo", TRUE }, { "./temp-files/*", "./temp-files/foo/bar", TRUE }, { "temp-files", "./my/temp-files", TRUE }, { "temp-files", "./my/temp-files/bar", TRUE }, { "temp-files", "./temp-files", TRUE }, { "temp-files", "./her-temp-files", FALSE }, { "temp-files", "./her/old-temp-files", FALSE }, { "temp-files", "./her/old-temp-files/bar", FALSE }, { "generated-*", "./my/generated-xyz", TRUE }, { "generated-*", "./my/generated-xyz/bar", TRUE }, { "generated-*", "./generated-xyz", TRUE }, { "generated-*", "./her-generated-xyz", FALSE }, { "generated-*", "./her/old-generated-xyz", FALSE }, { "generated-*", "./her/old-generated-xyz/bar", FALSE }, { "*.iso", "./my/amanda.iso", TRUE }, { "*.iso", "./amanda.iso", TRUE }, { "proxy/local/cache", "./usr/proxy/local/cache", TRUE }, { "proxy/local/cache", "./proxy/local/cache", TRUE }, { "proxy/local/cache", "./proxy/local/cache/7a", TRUE }, { NULL, NULL, FALSE }, }, *t; for (t = tests; t->expr; t++) { gboolean matched = match_tar(t->expr, t->str); if (!!matched != !!t->should_match) { ok = FALSE; if (t->should_match) { g_fprintf(stderr, "%s should have matched tar %s\n", t->str, t->expr); } else { g_fprintf(stderr, "%s unexpectedly matched tar %s\n", t->str, t->expr); } } } return ok; }