diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-29 16:08:38 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-04-30 14:41:42 +0200 |
commit | 7a39921d7fff089c87ac183d3c0d6e42e5cbaa04 (patch) | |
tree | 723bce4ebe163fc939919bd877c2919f48d84534 /lib/util/src | |
parent | 4390eddccfb3918291e7b8e4d708411f9b828c04 (diff) |
Move the pattern matching from gensquashfs to dir_tree_iterator_t
A simple unit test is added that mainly checks for the behavior of
recursing into a sub-tree and only matching the children at the end,
but not reporting the parents that don't match. The behavior is
inteded to immitate the `find` command.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/util/src')
-rw-r--r-- | lib/util/src/dir_tree_iterator.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/util/src/dir_tree_iterator.c b/lib/util/src/dir_tree_iterator.c index 55fbabb..a63209b 100644 --- a/lib/util/src/dir_tree_iterator.c +++ b/lib/util/src/dir_tree_iterator.c @@ -216,6 +216,23 @@ retry: } } + if (it->cfg.name_pattern != NULL) { + if (it->cfg.flags & DIR_SCAN_MATCH_FULL_PATH) { + ret = fnmatch(it->cfg.name_pattern, + ent->name, FNM_PATHNAME); + } else { + const char *name = strrchr(ent->name, '/'); + name = (name == NULL) ? ent->name : (name + 1); + + ret = fnmatch(it->cfg.name_pattern, name, 0); + } + + if (ret != 0) { + free(ent); + goto retry; + } + } + *out = ent; return it->state; fail: |