summaryrefslogtreecommitdiffstats
path: root/bfs.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2015-09-26 12:54:18 -0400
committerTavian Barnes <tavianator@tavianator.com>2015-09-26 12:54:18 -0400
commitd0243a72d56326af2c5ff7b7b3823dbe57b3bd4c (patch)
tree10a9f4223ca594252392b8bf46b80e031f9dbb86 /bfs.c
parent4bedd5a6f7b12e0923dd6fa180dcaad7e1f75fc2 (diff)
downloadbfs-d0243a72d56326af2c5ff7b7b3823dbe57b3bd4c.tar.xz
Optimize -maxdepth in -depth 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);
}