summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-11-17 16:02:57 -0500
committerTavian Barnes <tavianator@tavianator.com>2022-11-17 16:02:57 -0500
commitda02defb91c3a1bda0ea7e653d81f997f1c8884a (patch)
tree2b58212b064989b01c90d7d78fa00cedc9e4bec2
parent3604eeddb8a317c0745e92680d0405c645fbe247 (diff)
downloadbfs-da02defb91c3a1bda0ea7e653d81f997f1c8884a.tar.xz
expr: Don't use reftime for -ls
reftime is part of a different union than the print actions are supposed to use.
-rw-r--r--src/ctx.c5
-rw-r--r--src/ctx.h4
-rw-r--r--src/eval.c2
-rw-r--r--src/parse.c10
4 files changed, 12 insertions, 9 deletions
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 <assert.h>
#include <errno.h>
#include <limits.h>
@@ -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 <stdbool.h>
#include <stddef.h>
#include <sys/resource.h>
+#include <time.h>
/**
* 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) {