From 224f01a6508cececfb327f7692fcab2afb992805 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 15 Sep 2015 17:47:22 -0400 Subject: Fix -maxdepth handling when -depth is set. Lost some data due to this bug :(. --- bfs.c | 2 +- tests.sh | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bfs.c b/bfs.c index 1383589..359df63 100644 --- a/bfs.c +++ b/bfs.c @@ -873,7 +873,7 @@ static int cmdline_callback(const char *fpath, const struct BFTW *ftwbuf, void * state.ret = BFTW_SKIP_SUBTREE; } - if (ftwbuf->level >= cl->mindepth) { + if (ftwbuf->level >= cl->mindepth && ftwbuf->level <= cl->maxdepth) { cl->expr->eval(cl->expr, &state); } diff --git a/tests.sh b/tests.sh index f7d16fd..9c7c397 100755 --- a/tests.sh +++ b/tests.sh @@ -47,12 +47,24 @@ function test_0005() { find_diff "$1" -maxdepth 1 } -for i in {1..5}; do +function test_0006() { + basic_structure "$1" + find_diff "$1" -mindepth 1 -depth +} + +function test_0007() { + basic_structure "$1" + find_diff "$1" -maxdepth 1 -depth +} + +for i in {1..7}; do dir="$(mktemp -d)" - test_$(printf '%04d' $i) "$dir" + test="test_$(printf '%04d' $i)" + "$test" "$dir" status=$? rm -rf "$dir" if [ $status -ne 0 ]; then + echo "$test failed!" >&2 exit $status fi done -- cgit v1.2.3