From 35e854998e2ab2155875683411beb0518236da18 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 1 Feb 2013 12:51:12 -0800 Subject: [PATCH] Fix timestamp bug when write-region appends nothing. * fileio.c (Fwrite_region): When neither O_EXCL nor O_TRUNC is used, the file's time stamp doesn't change if Emacs happens to write nothing to the file, and on a buggy file system this could cause Emacs to incorrectly infer that the file system doesn't have the bug. Avoid this problem by inhibiting the inference in this case. Fixes: debbugs:13149 --- src/ChangeLog | 9 +++++++++ src/fileio.c | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 9682da2423..b4c3195973 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2013-02-01 Paul Eggert + + Fix timestamp bug when write-region appends nothing (Bug#13149). + * fileio.c (Fwrite_region): When neither O_EXCL nor O_TRUNC is used, + the file's time stamp doesn't change if Emacs happens to write nothing + to the file, and on a buggy file system this could cause Emacs to + incorrectly infer that the file system doesn't have the bug. + Avoid this problem by inhibiting the inference in this case. + 2013-02-01 Dmitry Antipov * window.h (struct window): Convert base_line_number, base_line_pos diff --git a/src/fileio.c b/src/fileio.c index a8218fcd79..fb6ecfedeb 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -5036,7 +5036,11 @@ This calls `write-region-annotate-functions' at the start, and && st.st_dev == st1.st_dev && st.st_ino == st1.st_ino) { EMACS_TIME modtime1 = get_stat_mtime (&st1); - if (EMACS_TIME_EQ (modtime, modtime1) + /* 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 + && EMACS_TIME_EQ (modtime, modtime1) && st.st_size == st1.st_size) { timestamp_file_system = st.st_dev; -- 2.20.1