#############################################################################*/
#include <errno.h>
+#include <fnmatch.h>
#include <fts.h>
#include <stdlib.h>
#include <string.h>
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)
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,
};
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);