From fb7a61add741b28ae6c91787373bdb544b2e751b Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 17 Dec 2018 22:05:49 -0500 Subject: Add new -capable test --- bfs.1 | 5 +++++ eval.c | 7 +++++++ eval.h | 1 + parse.c | 20 ++++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/bfs.1 b/bfs.1 index b6e4e8a..2140a6b 100644 --- a/bfs.1 +++ b/bfs.1 @@ -612,6 +612,11 @@ otherwise). .PP Tests: .TP +.B \-capable +Match files with POSIX.1e +.BR capabilities (7) +set. +.TP .B \-hidden Match hidden files (those beginning with .IR . ). diff --git a/eval.c b/eval.c index a170967..44e4a6d 100644 --- a/eval.c +++ b/eval.c @@ -196,6 +196,13 @@ bool eval_access(const struct expr *expr, struct eval_state *state) { return xfaccessat(ftwbuf->at_fd, ftwbuf->at_path, expr->idata) == 0; } +/** + * -capable test. + */ +bool eval_capable(const struct expr *expr, struct eval_state *state) { + return bfs_check_capabilities(state->ftwbuf); +} + /** * Get the given timespec field out of a stat buffer. */ diff --git a/eval.h b/eval.h index d826176..52bda54 100644 --- a/eval.h +++ b/eval.h @@ -24,6 +24,7 @@ bool eval_true(const struct expr *expr, struct eval_state *state); bool eval_false(const struct expr *expr, struct eval_state *state); bool eval_access(const struct expr *expr, struct eval_state *state); +bool eval_capable(const struct expr *expr, struct eval_state *state); bool eval_perm(const struct expr *expr, struct eval_state *state); bool eval_newer(const struct expr *expr, struct eval_state *state); diff --git a/parse.c b/parse.c index 7010f05..a1b60e3 100644 --- a/parse.c +++ b/parse.c @@ -962,6 +962,22 @@ static struct expr *parse_time(struct parser_state *state, int field, int unit) return expr; } +/** + * Parse -capable. + */ +static struct expr *parse_capable(struct parser_state *state, int flag, int arg2) { +#if BFS_HAS_POSIX1E_CAPABILITIES + struct expr *expr = parse_nullary_test(state, eval_capable); + if (expr) { + expr->cost = 2*STAT_COST; + } + return expr; +#else + cfprintf(state->cmdline->cerr, "%{er}error: %s is missing platform support.%{rs}\n", state->argv[0]); + return NULL; +#endif +} + /** * Parse -(no)?color. */ @@ -2464,6 +2480,9 @@ static struct expr *parse_help(struct parser_state *state, int arg1, int arg2) { cfprintf(cout, " Turn colors on or off (default: %{blu}-color%{rs} if outputting to a terminal,\n"); cfprintf(cout, " %{blu}-nocolor%{rs} otherwise)\n\n"); + cfprintf(cout, " %{blu}-capable%{rs}\n"); + cfprintf(cout, " Match files with POSIX.1e capabilities set\n\n"); + cfprintf(cout, " %{blu}-hidden%{rs}\n"); cfprintf(cout, " %{blu}-nohidden%{rs}\n"); cfprintf(cout, " Match hidden files, or filter them out\n\n"); @@ -2523,6 +2542,7 @@ static const struct table_entry parse_table[] = { {"-and"}, {"-anewer", false, parse_newer, BFS_STAT_ATIME}, {"-atime", false, parse_time, BFS_STAT_ATIME, DAYS}, + {"-capable", false, parse_capable}, {"-cmin", false, parse_time, BFS_STAT_CTIME, MINUTES}, {"-cnewer", false, parse_newer, BFS_STAT_CTIME}, {"-ctime", false, parse_time, BFS_STAT_CTIME, DAYS}, -- cgit v1.2.3