emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111664: Avoid file time stamp bug on


From: Paul Eggert
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111664: Avoid file time stamp bug on MS-Windows.
Date: Sat, 02 Feb 2013 11:18:00 -0800
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111664
fixes bug: http://debbugs.gnu.org/13149
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Sat 2013-02-02 11:18:00 -0800
message:
  Avoid file time stamp bug on MS-Windows.
  
  * fileio.c (Fwrite_region): Don't use the heuristic on empty files,
  as FAT32 doesn't update time stamps when truncating them.
  Also, check that a file time stamp is not a multiple of 100 ns;
  this should catch all instances of the problem on MS-Windows,
  as its native file system resolution is 100 ns or worse, and
  checking for a non-multiple of 100 ns should impose only a small
  overhead on systems with ns resolution.
modified:
  src/ChangeLog
  src/fileio.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-02-02 17:14:24 +0000
+++ b/src/ChangeLog     2013-02-02 19:18:00 +0000
@@ -1,3 +1,14 @@
+2013-02-02  Paul Eggert  <address@hidden>
+
+       Avoid file time stamp bug on MS-Windows (Bug#13149).
+       * fileio.c (Fwrite_region): Don't use the heuristic on empty files,
+       as FAT32 doesn't update time stamps when truncating them.
+       Also, check that a file time stamp is not a multiple of 100 ns;
+       this should catch all instances of the problem on MS-Windows,
+       as its native file system resolution is 100 ns or worse, and
+       checking for a non-multiple of 100 ns should impose only a small
+       overhead on systems with ns resolution.
+
 2013-02-02  Eli Zaretskii  <address@hidden>
 
        Avoid encoding file names on MS-Windows when they need to be run

=== modified file 'src/fileio.c'
--- a/src/fileio.c      2013-02-02 17:14:24 +0000
+++ b/src/fileio.c      2013-02-02 19:18:00 +0000
@@ -5020,11 +5020,22 @@
          if (fstat (desc1, &st1) == 0
              && st.st_dev == st1.st_dev && st.st_ino == st1.st_ino)
            {
+             /* Use the heuristic if it appears to be valid.  With neither
+                O_EXCL nor O_TRUNC, if Emacs happened to write nothing to the
+                file, the time stamp won't change.  Also, some non-POSIX
+                systems don't update an empty file's time stamp when
+                truncating it.  Finally, file systems with 100 ns or worse
+                resolution sometimes seem to have bugs: on a system with ns
+                resolution, checking ns % 100 incorrectly avoids the heuristic
+                1% of the time, but the problem should be temporary as we will
+                try again on the next time stamp.  */
+             bool use_heuristic
+               = ((open_flags & (O_EXCL | O_TRUNC)) != 0
+                  && st.st_size != 0
+                  && EMACS_NSECS (modtime) % 100 != 0);
+
              EMACS_TIME modtime1 = get_stat_mtime (&st1);
-             /* If neither O_EXCL nor O_TRUNC is used, and Emacs happened to
-                write nothing to the file, the file's time stamp won't change
-                so it should not be used in this heuristic.  */
-             if ((open_flags & (O_EXCL | O_TRUNC)) != 0
+             if (use_heuristic
                  && EMACS_TIME_EQ (modtime, modtime1)
                  && st.st_size == st1.st_size)
                {


reply via email to

[Prev in Thread] Current Thread [Next in Thread]