From: Michael Tremer Date: Tue, 6 Apr 2021 13:54:26 +0000 (+0000) Subject: filelists: Implement processing includes X-Git-Tag: 0.9.28~1285^2~439 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70aabbfdd987c0c9cb9bea9013cc551eb6a38d89;p=pakfire.git filelists: Implement processing includes Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/filelist.c b/src/libpakfire/filelist.c index 5d448e200..64bcea7d3 100644 --- a/src/libpakfire/filelist.c +++ b/src/libpakfire/filelist.c @@ -19,6 +19,7 @@ #############################################################################*/ #include +#include #include #include #include @@ -323,6 +324,33 @@ ERROR: return 1; } +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; + + int r; + + for (const char** include = includes; *include; include++) { + r = fnmatch(*include, path, 0); + + // Found a match + if (r == 0) + return 1; + + // No match found + else if (r == FNM_NOMATCH) + continue; + + // Any other error + else + return r; + } + + // No match + 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) @@ -339,14 +367,14 @@ static int pakfire_filelist_is_excluded(const char* path, const char** excludes) int pakfire_filelist_scan(PakfireFilelist list, const char* root, const char** includes, const char** excludes) { + DEBUG(list->pakfire, "Scanning %s...\n", root); + struct archive* reader = pakfire_make_archive_disk_reader(list->pakfire, 1); if (!reader) return 1; int r = 1; - // XXX handle includes - char* paths[] = { (char*)root, NULL, }; @@ -367,6 +395,15 @@ int pakfire_filelist_scan(PakfireFilelist list, const char* root, if (!path) continue; + // Skip what is not included + if (!pakfire_filelist_is_included(path, includes)) { + DEBUG(list->pakfire, "Skipping %s...\n", path); + + // We do not mark the whole tree as to skip because some matches might + // look for file extensions, etc. + continue; + } + // Skip excludes if (pakfire_filelist_is_excluded(path, excludes)) { DEBUG(list->pakfire, "Skipping %s...\n", path);