aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-25 16:33:15 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-25 16:37:41 +0100
commit7d2b3b077d7e204e64a1c57845524250c5b4a142 (patch)
treef3db19ebd254d3794b2c0c6aab495d7e531ea9aa
parentb0f6ab7ff26c1152ee4894a86f69b183cfabe94f (diff)
libfstree: allow the glob path to be empty
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--lib/fstree/fstree_from_file.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/fstree/fstree_from_file.c b/lib/fstree/fstree_from_file.c
index 3bf8cd1..d2f0b4a 100644
--- a/lib/fstree/fstree_from_file.c
+++ b/lib/fstree/fstree_from_file.c
@@ -238,7 +238,7 @@ static int glob_files(fstree_t *fs, const char *filename, size_t line_num,
DIR_SCAN_NO_FIFO | DIR_SCAN_NO_FILE | DIR_SCAN_NO_SLINK |
DIR_SCAN_NO_SOCK;
- while (*extra != '\0') {
+ while (extra != NULL && *extra != '\0') {
count = sizeof(glob_scan_flags) / sizeof(glob_scan_flags[0]);
for (i = 0; i < count; ++i) {
@@ -318,17 +318,19 @@ static int glob_files(fstree_t *fs, const char *filename, size_t line_num,
}
}
- if (*extra == '\0') {
- fprintf(stderr, "%s: " PRI_SZ ": glob path missing.\n",
- filename, line_num);
- free(ctx.name_pattern);
- return -1;
- }
+ if (extra != NULL && *extra == '\0')
+ extra = NULL;
/* do the scan */
if (basepath == NULL) {
- ret = fstree_from_dir(fs, root, extra, glob_node_callback,
- &ctx, scan_flags);
+ if (extra == NULL) {
+ ret = fstree_from_dir(fs, root, ".", glob_node_callback,
+ &ctx, scan_flags);
+ } else {
+ ret = fstree_from_dir(fs, root, extra,
+ glob_node_callback,
+ &ctx, scan_flags);
+ }
} else {
ret = fstree_from_subdir(fs, root, basepath, extra,
glob_node_callback, &ctx,
@@ -357,7 +359,7 @@ static const struct callback_t {
{ "pipe", S_IFIFO, false, false, false, add_generic },
{ "sock", S_IFSOCK, false, false, false, add_generic },
{ "file", S_IFREG, false, false, false, add_file },
- { "glob", 0, true, true, true, glob_files },
+ { "glob", 0, false, true, true, glob_files },
};
#define NUM_HOOKS (sizeof(file_list_hooks) / sizeof(file_list_hooks[0]))