summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-02-27 14:35:19 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-02-27 14:35:19 -0500
commitba967212e94110986e4b7512a75a9e8aa519fd19 (patch)
tree7af4ba5bd3dd3b470f98bb328f5885d33787569e
parent5e94b28d4a62cd590f173e0358cb3272073e4585 (diff)
downloadbfs-ba967212e94110986e4b7512a75a9e8aa519fd19.tar.xz
Implement (most of) -newerXY.
-rw-r--r--parse.c81
-rwxr-xr-xtests.sh10
2 files changed, 88 insertions, 3 deletions
diff --git a/parse.c b/parse.c
index 4e487dc..aeac611 100644
--- a/parse.c
+++ b/parse.c
@@ -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;
diff --git a/tests.sh b/tests.sh
index 77ba586..a6c40b7 100755
--- a/tests.sh
+++ b/tests.sh
@@ -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=$?