From 6e9f52c9a8d51cac7db3b62e799fc32072c86443 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 5 Nov 2017 12:03:31 -0500 Subject: Add support for file birth/creation times on platforms that have it Fixes #19 --- eval.c | 56 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 62dbf55..fe89225 100644 --- a/eval.c +++ b/eval.c @@ -135,15 +135,15 @@ bool eval_access(const struct expr *expr, struct eval_state *state) { } /** - * -[acm]{min,time} tests. + * -[aBcm]?newer tests. */ -bool eval_acmtime(const struct expr *expr, struct eval_state *state) { +bool eval_newer(const struct expr *expr, struct eval_state *state) { const struct stat *statbuf = fill_statbuf(state); if (!statbuf) { return false; } - const struct timespec *time = NULL; + const struct timespec *time; switch (expr->time_field) { case ATIME: time = &statbuf->st_atim; @@ -154,32 +154,32 @@ bool eval_acmtime(const struct expr *expr, struct eval_state *state) { case MTIME: time = &statbuf->st_mtim; break; - } - assert(time); - time_t diff = timespec_diff(&expr->reftime, time); - switch (expr->time_unit) { - case MINUTES: - diff /= 60; - break; - case DAYS: - diff /= 60*60*24; +#if BFS_HAVE_ST_BIRTHTIM + case BTIME: + time = &statbuf->st_birthtim; break; +#endif + + default: + assert(false); + return false; } - return expr_cmp(expr, diff); + return time->tv_sec > expr->reftime.tv_sec + || (time->tv_sec == expr->reftime.tv_sec && time->tv_nsec > expr->reftime.tv_nsec); } /** - * -[ac]?newer tests. + * -[aBcm]{min,time} tests. */ -bool eval_acnewer(const struct expr *expr, struct eval_state *state) { +bool eval_time(const struct expr *expr, struct eval_state *state) { const struct stat *statbuf = fill_statbuf(state); if (!statbuf) { return false; } - const struct timespec *time = NULL; + const struct timespec *time; switch (expr->time_field) { case ATIME: time = &statbuf->st_atim; @@ -190,11 +190,29 @@ bool eval_acnewer(const struct expr *expr, struct eval_state *state) { case MTIME: time = &statbuf->st_mtim; break; + +#if BFS_HAVE_ST_BIRTHTIM + case BTIME: + time = &statbuf->st_birthtim; + break; +#endif + + default: + assert(false); + return false; } - assert(time); - return time->tv_sec > expr->reftime.tv_sec - || (time->tv_sec == expr->reftime.tv_sec && time->tv_nsec > expr->reftime.tv_nsec); + time_t diff = timespec_diff(&expr->reftime, time); + switch (expr->time_unit) { + case MINUTES: + diff /= 60; + break; + case DAYS: + diff /= 60*60*24; + break; + } + + return expr_cmp(expr, diff); } /** -- cgit v1.2.3