summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-08-16 09:24:30 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-08-16 09:33:34 -0400
commitc3f52a2e3c22a8e05b60f94b8344501b14e87794 (patch)
tree6d5c3d6fec021ba5814443e44b971e59ed5157e9 /src/eval.c
parente130daf99c1828c554c27d546274712624b81faa (diff)
downloadbfs-c3f52a2e3c22a8e05b60f94b8344501b14e87794.tar.xz
New -noerror option to suppress error messages
Closes: https://github.com/tavianator/bfs/issues/142
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/eval.c b/src/eval.c
index d139ed3..9676cf3 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -53,6 +53,8 @@ struct bfs_eval {
enum bftw_action action;
/** The bfs_eval() return value. */
int *ret;
+ /** The number of errors that have occurred. */
+ size_t *nerrors;
/** Whether to quit immediately. */
bool quit;
};
@@ -62,10 +64,16 @@ struct bfs_eval {
*/
_printf(2, 3)
static void eval_error(struct bfs_eval *state, const char *format, ...) {
+ const struct bfs_ctx *ctx = state->ctx;
+
+ ++*state->nerrors;
+ if (ctx->ignore_errors) {
+ return;
+ }
+
// By POSIX, any errors should be accompanied by a non-zero exit status
*state->ret = EXIT_FAILURE;
- const struct bfs_ctx *ctx = state->ctx;
CFILE *cerr = ctx->cerr;
bfs_error(ctx, "%pP: ", state->ftwbuf);
@@ -1389,6 +1397,8 @@ struct callback_args {
/** The set of seen files. */
struct trie *seen;
+ /** The number of errors that have occurred. */
+ size_t nerrors;
/** Eventual return value from bfs_eval(). */
int ret;
};
@@ -1407,6 +1417,7 @@ static enum bftw_action eval_callback(const struct BFTW *ftwbuf, void *ptr) {
state.ctx = ctx;
state.action = BFTW_CONTINUE;
state.ret = &args->ret;
+ state.nerrors = &args->nerrors;
state.quit = false;
// Check whether SIGINFO was delivered and show/hide the bar
@@ -1740,5 +1751,9 @@ int bfs_eval(struct bfs_ctx *ctx) {
sigunhook(info_hook);
bfs_bar_hide(args.bar);
+ if (args.nerrors > 0) {
+ bfs_warning(ctx, "suppressed errors: %zu\n", args.nerrors);
+ }
+
return args.ret;
}