From 96ca12560f5c4007891985f98fba94fd9c0dc241 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 20 Dec 2016 21:09:42 -0500 Subject: Support -[gu]id NAME like BSD find --- parse.c | 34 ++++++++++------------------------ tests.sh | 12 +++++++++++- tests/test_0118.out | 19 +++++++++++++++++++ tests/test_0119.out | 19 +++++++++++++++++++ 4 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 tests/test_0118.out create mode 100644 tests/test_0119.out diff --git a/parse.c b/parse.c index cba9a29..33f928b 100644 --- a/parse.c +++ b/parse.c @@ -974,14 +974,7 @@ static struct expr *parse_fprint0(struct parser_state *state, int arg1, int arg2 } /** - * Parse -gid N. - */ -static struct expr *parse_gid(struct parser_state *state, int arg1, int arg2) { - return parse_test_icmp(state, eval_gid); -} - -/** - * Parse -group. + * Parse -gid/-group. */ static struct expr *parse_group(struct parser_state *state, int arg1, int arg2) { const char *arg = state->argv[0]; @@ -994,8 +987,9 @@ static struct expr *parse_group(struct parser_state *state, int arg1, int arg2) struct group *grp = getgrnam(expr->sdata); if (grp) { expr->idata = grp->gr_gid; - } else if (isdigit(expr->sdata[0])) { - if (!parse_int(state, expr->sdata, &expr->idata, IF_LONG_LONG)) { + expr->cmp_flag = CMP_EXACT; + } else if (isdigit(expr->sdata[0]) || expr->sdata[0] == '+' || expr->sdata[0] == '-') { + if (!parse_icmp(state, expr->sdata, expr, 0)) { goto fail; } } else { @@ -1004,7 +998,6 @@ static struct expr *parse_group(struct parser_state *state, int arg1, int arg2) goto fail; } - expr->cmp_flag = CMP_EXACT; return expr; fail: @@ -1012,13 +1005,6 @@ fail: return NULL; } -/** - * Parse -uid N. - */ -static struct expr *parse_uid(struct parser_state *state, int arg1, int arg2) { - return parse_test_icmp(state, eval_uid); -} - /** * Parse -used N. */ @@ -1027,7 +1013,7 @@ static struct expr *parse_used(struct parser_state *state, int arg1, int arg2) { } /** - * Parse -user. + * Parse -uid/-user. */ static struct expr *parse_user(struct parser_state *state, int arg1, int arg2) { const char *arg = state->argv[0]; @@ -1040,8 +1026,9 @@ static struct expr *parse_user(struct parser_state *state, int arg1, int arg2) { struct passwd *pwd = getpwnam(expr->sdata); if (pwd) { expr->idata = pwd->pw_uid; - } else if (isdigit(expr->sdata[0])) { - if (!parse_int(state, expr->sdata, &expr->idata, IF_LONG_LONG)) { + expr->cmp_flag = CMP_EXACT; + } else if (isdigit(expr->sdata[0]) || expr->sdata[0] == '+' || expr->sdata[0] == '-') { + if (!parse_icmp(state, expr->sdata, expr, 0)) { goto fail; } } else { @@ -1050,7 +1037,6 @@ static struct expr *parse_user(struct parser_state *state, int arg1, int arg2) { goto fail; } - expr->cmp_flag = CMP_EXACT; return expr; fail: @@ -1809,7 +1795,7 @@ static const struct table_entry parse_table[] = { {"follow", false, parse_follow, BFTW_LOGICAL | BFTW_DETECT_CYCLES, true}, {"fprint", false, parse_fprint}, {"fprint0", false, parse_fprint0}, - {"gid", false, parse_gid}, + {"gid", false, parse_group}, {"group", false, parse_group}, {"help", false, parse_help}, {"hidden", false, parse_hidden}, @@ -1853,7 +1839,7 @@ static const struct table_entry parse_table[] = { {"size", false, parse_size}, {"true", false, parse_const, true}, {"type", false, parse_type, false}, - {"uid", false, parse_uid}, + {"uid", false, parse_user}, {"used", false, parse_used}, {"user", false, parse_user}, {"version", false, parse_version}, diff --git a/tests.sh b/tests.sh index 8848ebe..8d9a49b 100755 --- a/tests.sh +++ b/tests.sh @@ -735,9 +735,19 @@ function test_0117() { bfs_diff basic -depth -depth -2 } +function test_0118() { + [ "$BSD" ] || return 0 + bfs_diff basic -gid "$(id -gn)" +} + +function test_0119() { + [ "$BSD" ] || return 0 + bfs_diff basic -uid "$(id -un)" +} + result=0 -for i in {1..117}; do +for i in {1..119}; do test="test_$(printf '%04d' $i)" if [ -t 1 ]; then diff --git a/tests/test_0118.out b/tests/test_0118.out new file mode 100644 index 0000000..bb3cd8d --- /dev/null +++ b/tests/test_0118.out @@ -0,0 +1,19 @@ +basic +basic/a +basic/b +basic/c +basic/e +basic/g +basic/i +basic/j +basic/k +basic/l +basic/c/d +basic/e/f +basic/g/h +basic/j/foo +basic/k/foo +basic/l/foo +basic/k/foo/bar +basic/l/foo/bar +basic/l/foo/bar/baz diff --git a/tests/test_0119.out b/tests/test_0119.out new file mode 100644 index 0000000..bb3cd8d --- /dev/null +++ b/tests/test_0119.out @@ -0,0 +1,19 @@ +basic +basic/a +basic/b +basic/c +basic/e +basic/g +basic/i +basic/j +basic/k +basic/l +basic/c/d +basic/e/f +basic/g/h +basic/j/foo +basic/k/foo +basic/l/foo +basic/k/foo/bar +basic/l/foo/bar +basic/l/foo/bar/baz -- cgit v1.2.3