From 7a39921d7fff089c87ac183d3c0d6e42e5cbaa04 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 29 Apr 2023 16:08:38 +0200 Subject: 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 --- lib/util/src/dir_tree_iterator.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/util/src') 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: -- cgit v1.2.3