From 70fadadf1fc7e1bd09c3d0f451614a678277409c Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 1 Feb 2016 17:46:06 -0500 Subject: Add -gid and -uid support. --- bfs.h | 3 +++ eval.c | 24 ++++++++++++++++++++++++ parse.c | 4 ++++ tests.sh | 16 +++++++++++++++- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/bfs.h b/bfs.h index e4dffdd..a8efffb 100644 --- a/bfs.h +++ b/bfs.h @@ -125,6 +125,9 @@ bool eval_ctime(const expression *expr, eval_state *state); bool eval_mmin(const expression *expr, eval_state *state); bool eval_mtime(const expression *expr, eval_state *state); +bool eval_gid(const expression *expr, eval_state *state); +bool eval_uid(const expression *expr, eval_state *state); + bool eval_empty(const expression *expr, eval_state *state); bool eval_hidden(const expression *expr, eval_state *state); bool eval_type(const expression *expr, eval_state *state); diff --git a/eval.c b/eval.c index 243546e..b042339 100644 --- a/eval.c +++ b/eval.c @@ -178,6 +178,30 @@ bool eval_mtime(const expression *expr, eval_state *state) { return do_cmp(expr, to_days(diff)); } +/** + * -gid test. + */ +bool eval_gid(const expression *expr, eval_state *state) { + const struct stat *statbuf = fill_statbuf(state); + if (!statbuf) { + return false; + } + + return do_cmp(expr, statbuf->st_gid); +} + +/** + * -uid test. + */ +bool eval_uid(const expression *expr, eval_state *state) { + const struct stat *statbuf = fill_statbuf(state); + if (!statbuf) { + return false; + } + + return do_cmp(expr, statbuf->st_uid); +} + /** * -delete action. */ diff --git a/parse.c b/parse.c index 6983f16..d53a08b 100644 --- a/parse.c +++ b/parse.c @@ -409,6 +409,10 @@ static expression *parse_literal(parser_state *state) { return new_test_idata(state, eval_access, X_OK); } else if (strcmp(arg, "-false") == 0) { return &expr_false; + } else if (strcmp(arg, "-gid") == 0) { + return parse_test_icmp(state, arg, eval_gid); + } else if (strcmp(arg, "-uid") == 0) { + return parse_test_icmp(state, arg, eval_uid); } else if (strcmp(arg, "-hidden") == 0) { return new_test(state, eval_hidden); } else if (strcmp(arg, "-nohidden") == 0) { diff --git a/tests.sh b/tests.sh index bb24fe0..23a9aba 100755 --- a/tests.sh +++ b/tests.sh @@ -110,7 +110,21 @@ function test_0015() { find_diff "$1" -empty } -for i in {1..15}; do +function test_0016() { + basic_structure "$1" + find_diff "$1" -gid "$(id -g)" && \ + find_diff "$1" -gid +0 && \ + find_diff "$1" -gid -10000 +} + +function test_0017() { + basic_structure "$1" + find_diff "$1" -uid "$(id -u)" && \ + find_diff "$1" -uid +0 && \ + find_diff "$1" -uid -10000 +} + +for i in {1..17}; do dir="$(mktemp -d "${TMPDIR:-/tmp}"/bfs.XXXXXXXXXX)" test="test_$(printf '%04d' $i)" "$test" "$dir" -- cgit v1.2.3