Does what is says on the tin.

-   Oliver Webb <aquahobby...@proton.me>

P.S. Busybox test doesn't seem to care about sub-second precision in -ot/-nt:
https://git.busybox.net/busybox/tree/coreutils/test.c#n630 
From ef9a3f6981c77de29f75c24c95aba7ed0fee2f94 Mon Sep 17 00:00:00 2001
From: Oliver Webb <aquahobby...@proton.me>
Date: Tue, 6 Aug 2024 12:12:09 -0500
Subject: [PATCH] test -ot -nt use mtime, nanosecond correction, and tests

---
 tests/test.test   |  5 ++++-
 toys/posix/test.c | 10 ++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/tests/test.test b/tests/test.test
index 185eab8b..a40902d3 100644
--- a/tests/test.test
+++ b/tests/test.test
@@ -114,14 +114,17 @@ testing "-lt" "arith_test -lt" "l" "" ""
 testing "-le" "arith_test -le" "le" "" ""
 
 touch oldfile -d 1970-01-01
-touch newfile -d 2031-01-01
+touch newfile -d 2031-01-01T00:00:00.5
+ln -s newfile samefile
 
 testcmd "-ef" "newfile -ef newfile && echo yes" "yes\n" "" ""
+testcmd "-ef link" "newfile -ef samefile && echo yes" "yes\n" "" ""
 testcmd "-ef2" "newfile -ef oldfile || echo no" "no\n" "" ""
 testcmd "-ot" "oldfile -ot newfile && echo yes" "yes\n" "" ""
 testcmd "-ot2" "oldfile -ot oldfile || echo no" "no\n" "" ""
 testcmd "-nt" "newfile -nt oldfile && echo yes" "yes\n" "" ""
 testcmd "-nt2" "oldfile -nt newfile || echo no" "no\n" "" ""
+testcmd "-nt2" "oldfile -nt newfile || echo no" "no\n" "" ""
 
 testing "positional" "test -a == -a && echo yes" "yes\n" "" ""
 testing "! stacks" 'test \! \! \! \! 2 -eq 2 && echo yes' "yes\n" "" ""
diff --git a/toys/posix/test.c b/toys/posix/test.c
index 8395b8d3..44a964db 100644
--- a/toys/posix/test.c
+++ b/toys/posix/test.c
@@ -98,10 +98,12 @@ static int do_test(char **args, int *count)
       if (i==8) return a < b;
       if (i==10) return a<= b;
       if (i==12) return (st1.st_dev==st2.st_dev) && (st1.st_ino==st2.st_ino);
-      if (i==14) return (st1.st_atim.tv_sec < st2.st_atim.tv_sec) ||
-        (st1.st_atim.tv_nsec < st2.st_atim.tv_nsec);
-      if (i==16) return (st1.st_atim.tv_sec > st2.st_atim.tv_sec) ||
-        (st1.st_atim.tv_nsec > st2.st_atim.tv_nsec);
+      if (i==14) return (st1.st_mtim.tv_sec < st2.st_mtim.tv_sec) ||
+        (st1.st_mtim.tv_sec == st2.st_mtim.tv_sec &&
+        st1.st_mtim.tv_nsec < st2.st_mtim.tv_nsec);
+      if (i==16) return (st1.st_mtim.tv_sec > st2.st_mtim.tv_sec) ||
+        (st1.st_mtim.tv_sec == st2.st_mtim.tv_sec &&
+        st1.st_mtim.tv_nsec > st2.st_mtim.tv_nsec);
     }
   }
   s = *args;
-- 
2.46.0

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to