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

From: Paul Eggert <[email-masked]>
Date: Thu, 17 Jan 2013 21:01:37 -0800

On 01/17/2013 08:36 PM, Dmitry Gutov wrote:
> The time stamps were identical in all combinations:

Did vboxsf and/or cifs report time stamps that
were not on 100-ns boundaries?  That would be a bug.

How about the following program?  What does it output?

#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>

static int
report_times (int fd, char const *file)
{
  struct stat fst, lst, st;
  if (fstat (fd, &fst) != 0)
    return perror ("fstat"), -1;
  if (lstat (file, &lst) != 0)
    return perror ("lstat"), -1;
  if (stat (file, &st) != 0)
    return perror ("stat"), -1;
  printf ("%ld.%09ld fstat\n", (long) fst.st_mtim.tv_sec, fst.st_mtim.tv_nsec);
  printf ("%ld.%09ld lstat\n", (long) lst.st_mtim.tv_sec, lst.st_mtim.tv_nsec);
  printf ("%ld.%09ld stat\n", (long) st.st_mtim.tv_sec, st.st_mtim.tv_nsec);
  printf ("\n");
  return 0;
}

int
main (void)
{
  static char const file[] = "foo";
  struct timespec interval;
  int fd;
  unlink (file);
  fd = open (file, O_CREAT | O_WRONLY, -1);
  if (fd < 0)
    return perror ("open"), 1;
  if (report_times (fd, file) != 0)
    return 1;
  interval.tv_sec = 0;
  interval.tv_nsec = 10000000;
  if (nanosleep (&interval, 0) != 0)
    return perror ("nanosleep"), 1;
  if (write (fd, file, sizeof file - 1) != sizeof file - 1)
    return perror ("write"), 1;
  if (report_times (fd, file) != 0)
    return 1;
  return 0;
}