diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-02-27 14:35:19 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-02-27 14:35:19 -0500 |
commit | ba967212e94110986e4b7512a75a9e8aa519fd19 (patch) | |
tree | 7af4ba5bd3dd3b470f98bb328f5885d33787569e | |
parent | 5e94b28d4a62cd590f173e0358cb3272073e4585 (diff) | |
download | bfs-ba967212e94110986e4b7512a75a9e8aa519fd19.tar.xz |
Implement (most of) -newerXY.
-rw-r--r-- | parse.c | 81 | ||||
-rwxr-xr-x | tests.sh | 10 |
2 files changed, 88 insertions, 3 deletions
@@ -660,6 +660,85 @@ static struct expr *parse_lname(struct parser_state *state, bool casefold) { } /** + * Parse -newerXY. + */ +static struct expr *parse_newerxy(struct parser_state *state) { + const char *arg = state->args[0]; + if (strlen(arg) != 8) { + pretty_error(state->cmdline->stderr_colors, + "error: Expected -newerXY; found %s.\n", arg); + return NULL; + } + + struct expr *expr = parse_unary_test(state, eval_acnewer); + if (!expr) { + return NULL; + } + + switch (arg[6]) { + case 'a': + expr->timefield = ATIME; + break; + case 'c': + expr->timefield = CTIME; + break; + case 'm': + expr->timefield = MTIME; + break; + + case 'B': + pretty_error(state->cmdline->stderr_colors, + "error: %s: File birth times ('B') are not supported.\n", arg); + free(expr); + return NULL; + + default: + pretty_error(state->cmdline->stderr_colors, + "error: %s: For -newerXY, X should be 'a', 'c', 'm', or 'B'.\n", arg); + free(expr); + return NULL; + } + + if (arg[7] == 't') { + pretty_error(state->cmdline->stderr_colors, + "error: %s: Explicit reference times ('t') are not supported.\n", arg); + free(expr); + return NULL; + } else { + struct stat sb; + if (stat_arg(state, expr, &sb) != 0) { + return NULL; + } + + switch (arg[7]) { + case 'a': + expr->reftime = sb.st_atim; + break; + case 'c': + expr->reftime = sb.st_ctim; + break; + case 'm': + expr->reftime = sb.st_mtim; + break; + + case 'B': + pretty_error(state->cmdline->stderr_colors, + "error: %s: File birth times ('B') are not supported.\n", arg); + free(expr); + return NULL; + + default: + pretty_error(state->cmdline->stderr_colors, + "error: %s: For -newerXY, Y should be 'a', 'c', 'm', 'B', or 't'.\n", arg); + free(expr); + return NULL; + } + } + + return expr; +} + +/** * Parse -noleaf. */ static struct expr *parse_noleaf(struct parser_state *state) { @@ -928,6 +1007,8 @@ static struct expr *parse_literal(struct parser_state *state) { return parse_name(state, false); } else if (strcmp(arg, "-newer") == 0) { return parse_acnewer(state, MTIME); + } else if (strncmp(arg, "-newer", 6) == 0) { + return parse_newerxy(state); } else if (strcmp(arg, "-nocolor") == 0) { cmdline->stdout_colors = NULL; cmdline->stderr_colors = NULL; @@ -256,14 +256,18 @@ function test_0046() { } function test_0047() { - find_diff -L "$basic" -daystart -mtime 0 + find_diff "$basic" -daystart -mtime 0 } function test_0048() { - find_diff -L "$basic" -daystart -daystart -mtime 0 + find_diff "$basic" -daystart -daystart -mtime 0 } -for i in {1..48}; do +function test_0049() { + find_diff "$basic" -newermc "$basic/e/f" +} + +for i in {1..49}; do test="test_$(printf '%04d' $i)" "$test" "$dir" status=$? |