return 0;
}
-static int pakfire_filelist_is_included(const char* path, const char** includes) {
- // If the includes list is empty, everything is included
- if (!includes)
- return 1;
-
+static int pakfire_filelist_match_patterns(const char* path, const char** patterns) {
int r;
- for (const char** include = includes; *include; include++) {
- // "/" includes everything
- if (strcmp(*include, "/") == 0)
- return 1;
-
+ for (const char** pattern = patterns; *pattern; pattern++) {
// Match any subdirectories
- if (pakfire_string_startswith(path, *include))
+ if (pakfire_string_startswith(path, *pattern))
return 1;
// Skip fnmatch if the pattern doesn't have any globbing characters
- if (!is_glob(*include))
+ if (!is_glob(*pattern))
continue;
- r = fnmatch(*include, path, 0);
+ r = fnmatch(*pattern, path, 0);
// Found a match
if (r == 0)
return 0;
}
-static int pakfire_filelist_is_excluded(const char* path, const char** excludes) {
- // If the exclude list is empty, nothing can be excluded
- if (!excludes)
- return 0;
-
- for (const char** exclude = excludes; *exclude; exclude++) {
- if (pakfire_string_startswith(path, *exclude))
- return 1;
- }
-
- // No match
- return 0;
-}
-
int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root,
const char** includes, const char** excludes) {
struct pakfire_file* file = NULL;
continue;
// Skip what is not included
- if (!pakfire_filelist_is_included(path, includes)) {
+ if (includes && !pakfire_filelist_match_patterns(path, includes)) {
DEBUG(list->pakfire, "Skipping %s...\n", path);
// We do not mark the whole tree as to skip because some matches might
}
// Skip excludes
- if (pakfire_filelist_is_excluded(path, excludes)) {
+ if (excludes && pakfire_filelist_match_patterns(path, excludes)) {
DEBUG(list->pakfire, "Skipping %s...\n", path);
r = fts_set(tree, node, FTS_SKIP);