Skip to content

Commit

Permalink
expr: Don't use reftime for -ls
Browse files Browse the repository at this point in the history
reftime is part of a different union than the print actions are supposed
to use.
  • Loading branch information
tavianator committed Nov 17, 2022
1 parent 3604eed commit da02def
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -109,6 +110,10 @@ struct bfs_ctx *bfs_ctx_new(void) {
goto fail;
}

if (xgettime(&ctx->now) != 0) {
goto fail;
}

return ctx;

fail:
Expand Down
4 changes: 4 additions & 0 deletions src/ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <sys/resource.h>
#include <time.h>

/**
* Various debugging flags.
Expand Down Expand Up @@ -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;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 2 additions & 8 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -3892,18 +3890,14 @@ 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) {
// Operate depth-first when invoked as "find"
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) {
Expand Down

0 comments on commit da02def

Please sign in to comment.