summaryrefslogtreecommitdiffstats
path: root/bfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'bfs.c')
-rw-r--r--bfs.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/bfs.c b/bfs.c
index 5e166de..7669e6d 100644
--- a/bfs.c
+++ b/bfs.c
@@ -891,7 +891,17 @@ static bftw_action cmdline_callback(struct BFTW *ftwbuf, void *ptr) {
state.action = BFTW_SKIP_SUBTREE;
}
- if (ftwbuf->depth >= cl->mindepth && ftwbuf->depth <= cl->maxdepth) {
+ // In -depth mode, only handle directories on the BFTW_POST visit
+ bftw_visit expected_visit = BFTW_PRE;
+ if ((cl->flags & BFTW_DEPTH)
+ && ftwbuf->typeflag == BFTW_DIR
+ && ftwbuf->depth < cl->maxdepth) {
+ expected_visit = BFTW_POST;
+ }
+
+ if (ftwbuf->visit == expected_visit
+ && ftwbuf->depth >= cl->mindepth
+ && ftwbuf->depth <= cl->maxdepth) {
cl->expr->eval(cl->expr, &state);
}