The attcached patch enhances "test" and "[" to take account of the
nanoseconds part of the mtime when evaluating "test A -nt B" and "test
A -ot B".

Regards,
James.

2005-07-17  James Youngman  <[EMAIL PROTECTED]>

        * src/test.c (age_of): Return the nanoseconds part of the
        timestamp if this is available.
        * configure.ac: Determine if 'struct stat' has a member st_mtim
          which contains the nanoseconds part of the mtime.

Index: configure.ac
===================================================================
RCS file: /cvsroot/coreutils/coreutils/configure.ac,v
retrieving revision 1.59
diff -u -r1.59 configure.ac
--- configure.ac        9 Jul 2005 07:36:33 -0000       1.59
+++ configure.ac        17 Jul 2005 22:34:58 -0000
@@ -52,6 +52,8 @@
 
 gl_WINSIZE_IN_PTEM
 
+AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec],,,[#include <sys/stat.h>])
+
 AC_MSG_CHECKING(whether localtime caches TZ)
 AC_CACHE_VAL(utils_cv_localtime_cache,
 [if test x$ac_cv_func_tzset = xyes; then
Index: src/test.c
===================================================================
RCS file: /cvsroot/coreutils/coreutils/src/test.c,v
retrieving revision 1.120
diff -u -r1.120 test.c
--- src/test.c  30 May 2005 07:34:23 -0000      1.120
+++ src/test.c  17 Jul 2005 22:34:58 -0000
@@ -160,14 +160,23 @@
 }
 
 /* Find the modification time of FILE, and stuff it into *AGE.
+   If the timestamp has a nonoseconds part, stuff that into *NS;
+   otherwise stuff zero into *NS.
    Return true if successful.  */
 static bool
-age_of (char const *filename, time_t *age)
+age_of (char const *filename, time_t *age, long *ns)
 {
   struct stat finfo;
   bool ok = (stat (filename, &finfo) == 0);
   if (ok)
-    *age = finfo.st_mtime;
+    {
+      *age = finfo.st_mtime;
+#ifdef  HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+      *ns = finfo.st_mtim.tv_nsec;
+#else
+      *ns = 0;
+#endif
+    }
   return ok;
 }
 
@@ -319,13 +328,18 @@
              /* nt - newer than */
              time_t lt IF_LINT (= 0);
              time_t rt IF_LINT (= 0);
+             unsigned long l_ns IF_LINT (= 0);
+             unsigned long r_ns IF_LINT (= 0);
              bool le, re;
              pos += 3;
              if (l_is_l | r_is_l)
                test_syntax_error (_("-nt does not accept -l\n"), NULL);
-             le = age_of (argv[op - 1], &lt);
-             re = age_of (argv[op + 1], &rt);
-             return le > re || (le && lt > rt);
+             le = age_of (argv[op - 1], &lt, &l_ns);
+             re = age_of (argv[op + 1], &rt, &r_ns);
+             if (le && re && (rt == lt))
+               return l_ns > r_ns;
+             else
+               return le > re || (le && lt > rt);
            }
          break;
 
@@ -349,13 +363,18 @@
              /* ot - older than */
              time_t lt IF_LINT (= 0);
              time_t rt IF_LINT (= 0);
+             unsigned long l_ns IF_LINT (= 0);
+             unsigned long r_ns IF_LINT (= 0);
              bool le, re;
              pos += 3;
              if (l_is_l | r_is_l)
                test_syntax_error (_("-ot does not accept -l\n"), NULL);
-             le = age_of (argv[op - 1], &lt);
-             re = age_of (argv[op + 1], &rt);
-             return le < re || (re && lt < rt);
+             le = age_of (argv[op - 1], &lt, &l_ns);
+             re = age_of (argv[op + 1], &rt, &r_ns);
+             if (le && re && (lt == rt))
+               return l_ns < r_ns;
+             else
+               return le < re || (re && lt < rt);
            }
          break;
        }
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to