Re: [PATCH] find: -anewer: compare atime with reference file's atime, not mtime

2026-06-30 Thread Bernhard Voelker

Hi Weixie,

thanks for the patch and sorry for the delay.

On 3/4/26 14:09, Weixie Cui wrote:

-anewer was incorrectly using mtime for both the reference file and
the comparison.

what makes you think that this would be incorrect?

The manpage states:

  -anewer reference
 Like -newer, but test if the time of the last access of the current file 
is more
 recent than that of the last data modification of the reference file.

and the Texinfo manual is even more clear:

  [...] As such, ‘-anewer’ is equivalent to ‘-neweram’, ‘-cnewer’ to ‘-newercm’,
  and ‘-newer’ to ‘-newermm’.

Therefore, I think the behavior is correct and as documented.

Have a nice day,
Berny



[PATCH] find: -anewer: compare atime with reference file's atime, not mtime

2026-03-04 Thread Weixie Cui
From: Weixie Cui 

-anewer was incorrectly using mtime for both the reference file and
the comparison.  Fix to use atime for both, and add a regression test.

Signed-off-by: Weixie Cui 
---
 find/parser.c   |  4 ++--
 tests/find/newer.sh | 13 +
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/find/parser.c b/find/parser.c
index 054c2892..068c7dac 100644
--- a/find/parser.c
+++ b/find/parser.c
@@ -791,9 +791,9 @@ parse_anewer (const struct parser_table* entry, char 
**argv, int *arg_ptr)
 {
   struct predicate *our_pred = insert_primary (entry, arg);
   our_pred->args.reftime.xval = XVAL_ATIME;
-  our_pred->args.reftime.ts = get_stat_mtime (&stat_newer);
+  our_pred->args.reftime.ts = get_stat_atime (&stat_newer);
   our_pred->args.reftime.kind = COMP_GT;
-  our_pred->est_success_rate = estimate_timestamp_success_rate 
(stat_newer.st_mtime);
+  our_pred->est_success_rate = estimate_timestamp_success_rate 
(get_stat_atime (&stat_newer).tv_sec);
   return true;
 }
   return false;
diff --git a/tests/find/newer.sh b/tests/find/newer.sh
index 6cfc42b1..8e408ea1 100755
--- a/tests/find/newer.sh
+++ b/tests/find/newer.sh
@@ -62,4 +62,17 @@ else
   echo "Determining reference timestamp failed - skipping this part."
 fi
 
+# Regression test: -anewer must compare atime with reference file's atime,
+# not mtime.  With ref.atime=2020, ref.mtime=2026, file.atime=2023:
+# -anewer ref should match file (2023 > 2020).  Do not stat ref between
+# setting its atime and running find, or atime would be updated.
+rm -f "$TMPDIR/ref" "$TMPDIR/file" || framework_failure_
+touch -d "2026-01-01" "$TMPDIR/ref" || skip_ "touch -d failed"
+touch -a -d "2020-01-01" "$TMPDIR/ref" || skip_ "touch -a -d failed"
+touch "$TMPDIR/file" || framework_failure_
+touch -a -d "2023-01-01" "$TMPDIR/file" || skip_ "touch -a -d failed"
+echo "$TMPDIR/file" > exp-anewer || framework_failure_
+find "$TMPDIR" -maxdepth 1 -anewer "$TMPDIR/ref" -name file -print > out || 
fail=1
+compare exp-anewer out || fail=1
+
 Exit $fail
-- 
2.39.5 (Apple Git-154)