// Scan for files
r = pakfire_filelist_scan(filelist, build->buildroot,
- (const char**)includes, (const char**)excludes);
+ (const char**)includes, (const char**)excludes, PAKFIRE_FILELIST_EXTENDED_MATCHING);
if (r)
goto ERROR;
}
// Scan for all files in BUILDROOT
- r = pakfire_filelist_scan(filelist, build->buildroot, NULL, NULL);
+ r = pakfire_filelist_scan(filelist, build->buildroot, NULL, NULL, 0);
if (r)
goto ERROR;
goto ERROR;
// Scan for all files in BUILDROOT
- r = pakfire_filelist_scan(filelist, build->buildroot, NULL, NULL);
+ r = pakfire_filelist_scan(filelist, build->buildroot, NULL, NULL, 0);
if (r)
goto ERROR;
#############################################################################*/
#include <errno.h>
-#include <fnmatch.h>
#include <stdlib.h>
#include <sys/queue.h>
return pakfire_filelist_walk(removees, __pakfire_filelist_remove_one, list, 0);
}
-// Returns true if s contains globbing characters
-static int is_glob(const char* s) {
- if (strchr(s, '*'))
- return 1;
+static int pakfire_filelist_match_patterns(const char* path,
+ const char** patterns, const int flags) {
+ char buffer[PATH_MAX];
+ int r;
- if (strchr(s, '?'))
- return 1;
+ // Check inputs
+ if (!path || !patterns)
+ return -EINVAL;
+
+ for (const char** pattern = patterns; *pattern; pattern++) {
+ // Try to find a simple match
+ if (pakfire_path_match(*pattern, path))
+ return 1;
+ // If requested perform extended matching
+ if (flags & PAKFIRE_FILELIST_EXTENDED_MATCHING) {
+ // / matches everything
+ if (strcmp(*pattern, "/") == 0)
+ return 1;
+
+ // Try to match any sub-directories and files
+ r = pakfire_string_format(buffer, "%s/**", *pattern);
+ if (r)
+ return 1;
+
+ if (pakfire_path_match(buffer, path))
+ return 1;
+ }
+ }
+
+ // No match
return 0;
}
const char* root;
const char** includes;
const char** excludes;
+ const int flags;
};
static int pakfire_filelist_scan_filter(struct archive* archive, void* p,
if (!path || !*path)
return 0;
- // Store the new path
- archive_entry_set_pathname(entry, path);
-
// Skip excludes
- if (matches->excludes && pakfire_filelist_match_patterns(path, matches->excludes))
+ if (matches->excludes &&
+ pakfire_filelist_match_patterns(path, matches->excludes, matches->flags))
return 0;
// Skip what is not included
- if (matches->includes && !pakfire_filelist_match_patterns(path, matches->includes))
+ if (matches->includes &&
+ !pakfire_filelist_match_patterns(path, matches->includes, matches->flags))
return 0;
+ // Store the new path
+ archive_entry_set_pathname(entry, path);
+
return 1;
}
int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root,
- const char** includes, const char** excludes) {
+ const char** includes, const char** excludes, int flags) {
struct pakfire_file* file = NULL;
struct archive_entry* entry = NULL;
struct pakfire_filelist_matches matches = {
.root = root,
.includes = includes,
.excludes = excludes,
+ .flags = flags,
};
int r = 1;
if (!path)
return -1;
- int r = fnmatch(pattern, path, 0);
+ int r = pakfire_path_match(pattern, path);
if (r == 0)
return 1;
}
int pakfire_filelist_remove_all(struct pakfire_filelist* list,
struct pakfire_filelist* removees);
+enum pakfire_filelist_scan_flags {
+ PAKFIRE_FILELIST_EXTENDED_MATCHING = (1 << 0),
+};
+
int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root,
- const char** includes, const char** excludes);
+ const char** includes, const char** excludes, int flags);
int pakfire_filelist_contains(struct pakfire_filelist* list, const char* pattern);