From da02defb91c3a1bda0ea7e653d81f997f1c8884a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 17 Nov 2022 16:02:57 -0500 Subject: expr: Don't use reftime for -ls reftime is part of a different union than the print actions are supposed to use. --- src/ctx.c | 5 +++++ src/ctx.h | 4 ++++ src/eval.c | 2 +- src/parse.c | 10 ++-------- 4 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/ctx.c b/src/ctx.c index b9d15bb..0403299 100644 --- a/src/ctx.c +++ b/src/ctx.c @@ -23,6 +23,7 @@ #include "pwcache.h" #include "stat.h" #include "trie.h" +#include "xtime.h" #include #include #include @@ -109,6 +110,10 @@ struct bfs_ctx *bfs_ctx_new(void) { goto fail; } + if (xgettime(&ctx->now) != 0) { + goto fail; + } + return ctx; fail: diff --git a/src/ctx.h b/src/ctx.h index d32db59..6755d02 100644 --- a/src/ctx.h +++ b/src/ctx.h @@ -26,6 +26,7 @@ #include #include #include +#include /** * Various debugging flags. @@ -127,6 +128,9 @@ struct bfs_ctx { rlim_t nofile_soft; /** The initial RLIMIT_NOFILE hard limit. */ rlim_t nofile_hard; + + /** The current time. */ + struct timespec now; }; /** diff --git a/src/eval.c b/src/eval.c index dd147c9..4c9d807 100644 --- a/src/eval.c +++ b/src/eval.c @@ -708,7 +708,7 @@ bool eval_fls(const struct bfs_expr *expr, struct bfs_eval *state) { } time_t time = statbuf->mtime.tv_sec; - time_t now = expr->reftime.tv_sec; + time_t now = ctx->now.tv_sec; time_t six_months_ago = now - 6*30*24*60*60; time_t tomorrow = now + 24*60*60; struct tm tm; diff --git a/src/parse.c b/src/parse.c index fc30cd2..a1e32fd 100644 --- a/src/parse.c +++ b/src/parse.c @@ -284,7 +284,7 @@ struct parser_state { /** An "-ok"-type expression, if any. */ const struct bfs_expr *ok_expr; - /** The current time. */ + /** The current time (maybe modified by -daystart). */ struct timespec now; }; @@ -1527,7 +1527,6 @@ static struct bfs_expr *parse_fls(struct parser_state *state, int arg1, int arg2 expr_set_always_true(expr); expr->cost = PRINT_COST; - expr->reftime = state->now; return expr; fail: @@ -1772,7 +1771,6 @@ static struct bfs_expr *parse_ls(struct parser_state *state, int arg1, int arg2) } init_print_expr(state, expr); - expr->reftime = state->now; return expr; } @@ -3892,6 +3890,7 @@ struct bfs_ctx *bfs_parse_cmdline(int argc, char *argv[]) { .files0_arg = NULL, .files0_stdin_arg = NULL, .ok_expr = NULL, + .now = ctx->now, }; if (strcmp(xbasename(state.command), "find") == 0) { @@ -3899,11 +3898,6 @@ struct bfs_ctx *bfs_parse_cmdline(int argc, char *argv[]) { ctx->strategy = BFTW_DFS; } - if (xgettime(&state.now) != 0) { - parse_perror(&state, "xgettime()"); - goto fail; - } - ctx->exclude = &bfs_false; ctx->expr = parse_whole_expr(&state); if (!ctx->expr) { -- cgit v1.2.3