diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-03-05 13:53:40 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-03-05 13:53:40 -0500 |
commit | 037361965a14e1899020bf16c9112936e39020e8 (patch) | |
tree | b14529eeba8b28d6082b9b20a3c9c0cd97fbeda3 | |
parent | 0cc26b741deffefe181981022321549a3ed2bcff (diff) | |
download | bfs-037361965a14e1899020bf16c9112936e39020e8.tar.xz |
Implement -used.
This doesn't agree with find's output, but I think find is buggy here.
For example, find -used +0 is returning fewer results than find -used 1,
which makes no sense given that 1 is greater than 0.
-rw-r--r-- | bfs.h | 1 | ||||
-rw-r--r-- | eval.c | 15 | ||||
-rw-r--r-- | parse.c | 2 |
3 files changed, 18 insertions, 0 deletions
@@ -187,6 +187,7 @@ bool eval_access(const struct expr *expr, struct eval_state *state); bool eval_acmtime(const struct expr *expr, struct eval_state *state); bool eval_acnewer(const struct expr *expr, struct eval_state *state); +bool eval_used(const struct expr *expr, struct eval_state *state); bool eval_gid(const struct expr *expr, struct eval_state *state); bool eval_uid(const struct expr *expr, struct eval_state *state); @@ -174,6 +174,21 @@ bool eval_acnewer(const struct expr *expr, struct eval_state *state) { } /** + * -used test. + */ +bool eval_used(const struct expr *expr, struct eval_state *state) { + const struct stat *statbuf = fill_statbuf(state); + if (!statbuf) { + return false; + } + + time_t diff = timespec_diff(&statbuf->st_atim, &statbuf->st_ctim); + diff /= 60*60*24; + printf("%d\n", (int)diff); + return do_cmp(expr, diff); +} + +/** * -gid test. */ bool eval_gid(const struct expr *expr, struct eval_state *state) { @@ -1065,6 +1065,8 @@ static struct expr *parse_literal(struct parser_state *state) { case 'u': if (strcmp(arg, "-uid") == 0) { return parse_test_icmp(state, eval_uid); + } else if (strcmp(arg, "-used") == 0) { + return parse_test_icmp(state, eval_used); } else if (strcmp(arg, "-user") == 0) { return parse_user(state); } |