Subject: Re: bug#13149: 24.3.50; Emacs thinks file was changed outside Emacs, but it was not

From: Paul Eggert <[email-masked]>
Date: Mon, 14 Jan 2013 10:28:59 -0800

On 01/14/2013 06:57 AM, Dmitry Gutov wrote:
> any suggestions?

I'd guess it's a filesystem problem, where a file's
timestamp spontaneously changes even though the file
itself has not changed.  I had thought those bugs
fixed long ago, but maybe not.

Could you please start by trying the attached patch,
and then see what gets sent to stderr around the time
of the problem?  That might help us work around the
problem better than the old code did (it introduced
some race conditions).
=== modified file 'lib/stat-time.h'
--- lib/stat-time.h	2013-01-01 09:11:05 +0000
+++ lib/stat-time.h	2013-01-14 18:18:16 +0000
@@ -22,6 +22,7 @@
 
 #include <sys/stat.h>
 #include <time.h>
+#include <stdio.h>
 
 _GL_INLINE_HEADER_BEGIN
 #ifndef _GL_STAT_TIME_INLINE
@@ -136,14 +137,15 @@
 _GL_STAT_TIME_INLINE struct timespec
 get_stat_mtime (struct stat const *st)
 {
+  struct timespec t;
 #ifdef STAT_TIMESPEC
-  return STAT_TIMESPEC (st, st_mtim);
+  t = STAT_TIMESPEC (st, st_mtim);
 #else
-  struct timespec t;
   t.tv_sec = st->st_mtime;
   t.tv_nsec = get_stat_mtime_ns (st);
+#endif
+  fprintf (stderr, "stat_mtime=%ld.%09ld\n", (long) t.tv_sec, (long) t.tv_nsec);
   return t;
-#endif
 }
 
 /* Return *ST's birth time, if available; otherwise return a value