]> git.ipfire.org Git - pakfire.git/commitdiff
filelists: Implement processing includes
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Apr 2021 13:54:26 +0000 (13:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Apr 2021 13:54:26 +0000 (13:54 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/filelist.c

index 5d448e2004b515caa295fcb2961907e0cb29c61d..64bcea7d3ff6da89807f2bbe9f1726ea9a386dba 100644 (file)
@@ -19,6 +19,7 @@
 #############################################################################*/
 
 #include <errno.h>
+#include <fnmatch.h>
 #include <fts.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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);