summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-06-23 10:15:52 -0400
committerTavian Barnes <tavianator@tavianator.com>2019-06-25 01:18:47 -0400
commit71d8077dca5e5c407dff934d549fcfea53f83ede (patch)
treee5394798abeee9a6bedfcfe85bc489a098c7c339
parenteb62240bf67690a63b3d17626408d15408b93d57 (diff)
downloadbfs-71d8077dca5e5c407dff934d549fcfea53f83ede.tar.xz
bftw: Remove BFTW_SKIP_SIBLINGS
It's not used by bfs, and it's difficult to support in all search strategies.
-rw-r--r--bftw.c35
-rw-r--r--bftw.h4
-rw-r--r--eval.c13
3 files changed, 18 insertions, 34 deletions
diff --git a/bftw.c b/bftw.c
index 9217456..f1c4d92 100644
--- a/bftw.c
+++ b/bftw.c
@@ -1052,8 +1052,7 @@ static enum bftw_action bftw_visit(struct bftw_state *state, struct bftw_file *f
switch (ret) {
case BFTW_CONTINUE:
break;
- case BFTW_SKIP_SIBLINGS:
- case BFTW_SKIP_SUBTREE:
+ case BFTW_PRUNE:
case BFTW_STOP:
return ret;
default:
@@ -1062,13 +1061,13 @@ static enum bftw_action bftw_visit(struct bftw_state *state, struct bftw_file *f
}
if (visit != BFTW_PRE || ftwbuf->typeflag != BFTW_DIR) {
- return BFTW_SKIP_SUBTREE;
+ return BFTW_PRUNE;
}
if ((state->flags & BFTW_XDEV) && file) {
const struct bfs_stat *statbuf = bftw_stat(ftwbuf, ftwbuf->stat_flags);
if (statbuf && statbuf->dev != file->dev) {
- return BFTW_SKIP_SUBTREE;
+ return BFTW_PRUNE;
}
}
@@ -1232,9 +1231,7 @@ static int bftw_impl(const struct bftw_args *args) {
switch (bftw_visit(&state, NULL, path, BFTW_PRE)) {
case BFTW_CONTINUE:
break;
- case BFTW_SKIP_SIBLINGS:
- goto start;
- case BFTW_SKIP_SUBTREE:
+ case BFTW_PRUNE:
continue;
case BFTW_STOP:
goto done;
@@ -1245,7 +1242,6 @@ static int bftw_impl(const struct bftw_args *args) {
}
}
-start:
while (true) {
struct bftw_reader *reader = bftw_pop(&state);
if (!reader) {
@@ -1258,9 +1254,7 @@ start:
switch (bftw_visit(&state, reader->file, name, BFTW_PRE)) {
case BFTW_CONTINUE:
break;
- case BFTW_SKIP_SIBLINGS:
- goto next;
- case BFTW_SKIP_SUBTREE:
+ case BFTW_PRUNE:
continue;
case BFTW_STOP:
goto done;
@@ -1271,7 +1265,6 @@ start:
}
}
- next:
if (bftw_release_reader(&state, true) == BFTW_STOP) {
goto done;
}
@@ -1297,7 +1290,7 @@ struct bftw_dfs_state {
static enum bftw_action bftw_dfs_callback(const struct BFTW *ftwbuf, void *ptr) {
struct bftw_dfs_state *state = ptr;
enum bftw_action ret = state->delegate(ftwbuf, state->ptr);
- if (ret == BFTW_STOP || (ret == BFTW_SKIP_SIBLINGS && ftwbuf->depth == 0)) {
+ if (ret == BFTW_STOP || (ret == BFTW_PRUNE && ftwbuf->depth == 0)) {
state->quit = true;
}
return ret;
@@ -1362,19 +1355,19 @@ static enum bftw_action bftw_ids_callback(const struct BFTW *ftwbuf, void *ptr)
if (state->depth - ftwbuf->depth <= 1) {
return state->delegate(ftwbuf, state->ptr);
} else {
- return BFTW_SKIP_SUBTREE;
+ return BFTW_PRUNE;
}
}
if (ftwbuf->depth < state->depth) {
if (trie_find_str(state->pruned, ftwbuf->path)) {
- return BFTW_SKIP_SUBTREE;
+ return BFTW_PRUNE;
} else {
return BFTW_CONTINUE;
}
} else if (state->visit == BFTW_POST) {
if (trie_find_str(state->pruned, ftwbuf->path)) {
- return BFTW_SKIP_SUBTREE;
+ return BFTW_PRUNE;
}
}
@@ -1384,15 +1377,9 @@ static enum bftw_action bftw_ids_callback(const struct BFTW *ftwbuf, void *ptr)
switch (ret) {
case BFTW_CONTINUE:
- ret = BFTW_SKIP_SUBTREE;
+ ret = BFTW_PRUNE;
break;
- case BFTW_SKIP_SIBLINGS:
- // Can't be easily supported in this mode
- state->error = EINVAL;
- state->quit = true;
- ret = BFTW_STOP;
- break;
- case BFTW_SKIP_SUBTREE:
+ case BFTW_PRUNE:
if (ftwbuf->typeflag == BFTW_DIR) {
if (!trie_insert_str(state->pruned, ftwbuf->path)) {
state->error = errno;
diff --git a/bftw.h b/bftw.h
index e9b1132..573c5a9 100644
--- a/bftw.h
+++ b/bftw.h
@@ -150,10 +150,8 @@ enum bftw_typeflag bftw_typeflag(const struct BFTW *ftwbuf, enum bfs_stat_flag f
enum bftw_action {
/** Keep walking. */
BFTW_CONTINUE,
- /** Skip this path's siblings. */
- BFTW_SKIP_SIBLINGS,
/** Skip this path's children. */
- BFTW_SKIP_SUBTREE,
+ BFTW_PRUNE,
/** Stop walking. */
BFTW_STOP,
};
diff --git a/eval.c b/eval.c
index d2eea03..d89e62a 100644
--- a/eval.c
+++ b/eval.c
@@ -771,7 +771,7 @@ error:
* -prune action.
*/
bool eval_prune(const struct expr *expr, struct eval_state *state) {
- state->action = BFTW_SKIP_SUBTREE;
+ state->action = BFTW_PRUNE;
return true;
}
@@ -1042,7 +1042,7 @@ static bool eval_file_unique(struct eval_state *state, struct trie *seen) {
}
if (leaf->value) {
- state->action = BFTW_SKIP_SUBTREE;
+ state->action = BFTW_PRUNE;
return false;
} else {
leaf->value = leaf;
@@ -1151,8 +1151,7 @@ static const char *dump_bftw_visit(enum bftw_visit visit) {
static const char *dump_bftw_action(enum bftw_action action) {
static const char *actions[] = {
DUMP_BFTW_MAP(BFTW_CONTINUE),
- DUMP_BFTW_MAP(BFTW_SKIP_SIBLINGS),
- DUMP_BFTW_MAP(BFTW_SKIP_SUBTREE),
+ DUMP_BFTW_MAP(BFTW_PRUNE),
DUMP_BFTW_MAP(BFTW_STOP),
};
return actions[action];
@@ -1190,7 +1189,7 @@ static enum bftw_action cmdline_callback(const struct BFTW *ftwbuf, void *ptr) {
args->ret = EXIT_FAILURE;
eval_error(&state, "%s.\n", strerror(ftwbuf->error));
}
- state.action = BFTW_SKIP_SUBTREE;
+ state.action = BFTW_PRUNE;
goto done;
}
@@ -1203,12 +1202,12 @@ static enum bftw_action cmdline_callback(const struct BFTW *ftwbuf, void *ptr) {
if (cmdline->xargs_safe && strpbrk(ftwbuf->path, " \t\n\'\"\\")) {
args->ret = EXIT_FAILURE;
eval_error(&state, "Path is not safe for xargs.\n");
- state.action = BFTW_SKIP_SUBTREE;
+ state.action = BFTW_PRUNE;
goto done;
}
if (cmdline->maxdepth < 0 || ftwbuf->depth >= cmdline->maxdepth) {
- state.action = BFTW_SKIP_SUBTREE;
+ state.action = BFTW_PRUNE;
}
// In -depth mode, only handle directories on the BFTW_POST visit