From dbeed9a6816f011bbf29ff9e991f38b0d0d7e5ea Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 3 Jul 2012 16:51:32 -0700 Subject: [PATCH] * fileio.c: Improve handling of file time marker. (Bug#11852) (special_mtime): New function. (Finsert_file_contents, Fverify_visited_file_modtime): Use it to set special mtime values consistently. --- src/ChangeLog | 7 +++++++ src/fileio.c | 43 ++++++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index a82d2a03af8..87e92170261 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2012-07-03 Paul Eggert + + * fileio.c: Improve handling of file time marker. (Bug#11852) + (special_mtime): New function. + (Finsert_file_contents, Fverify_visited_file_modtime): + Use it to set special mtime values consistently. + 2012-07-03 Andreas Schwab * fileio.c (Finsert_file_contents): Properly handle st_mtime diff --git a/src/fileio.c b/src/fileio.c index 820dabff53e..6c3a3b206e8 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3215,6 +3215,17 @@ emacs_lseek (int fd, EMACS_INT offset, int whence) return lseek (fd, offset, whence); } +/* Return a special mtime value indicating the error number ERRNUM. */ +static EMACS_TIME +special_mtime (int errnum) +{ + EMACS_TIME t; + int ns = (errno == ENOENT || errno == EACCES || errno == ENOTDIR + ? NONEXISTENT_MODTIME_NSECS + : UNKNOWN_MODTIME_NSECS); + EMACS_SET_SECS_NSECS (t, 0, ns); + return t; +} DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, 1, 5, 0, @@ -3242,6 +3253,8 @@ variable `last-coding-system-used' to the coding system actually used. */) (Lisp_Object filename, Lisp_Object visit, Lisp_Object beg, Lisp_Object end, Lisp_Object replace) { struct stat st; + int file_status; + EMACS_TIME mtime; register int fd; ptrdiff_t inserted = 0; int nochange = 0; @@ -3310,19 +3323,22 @@ variable `last-coding-system-used' to the coding system actually used. */) /* Tell stat to use expensive method to get accurate info. */ Vw32_get_true_file_attributes = Qt; - total = stat (SSDATA (filename), &st); + file_status = stat (SSDATA (filename), &st); Vw32_get_true_file_attributes = tem; } - if (total < 0) #else - if (stat (SSDATA (filename), &st) < 0) + file_status = stat (SSDATA (filename), &st); #endif /* WINDOWSNT */ + + if (file_status == 0) + mtime = get_stat_mtime (&st); + else { badopen: save_errno = errno; if (NILP (visit)) report_file_error ("Opening input file", Fcons (orig_filename, Qnil)); - st.st_mtime = -1; + mtime = special_mtime (save_errno); st.st_size = -1; how_much = 0; if (!NILP (Vcoding_system_for_read)) @@ -4193,10 +4209,7 @@ variable `last-coding-system-used' to the coding system actually used. */) if (NILP (handler)) { - if (st.st_mtime == -1) - EMACS_SET_INVALID_TIME (current_buffer->modtime); - else - current_buffer->modtime = get_stat_mtime (&st); + current_buffer->modtime = mtime; current_buffer->modtime_size = st.st_size; BVAR (current_buffer, filename) = orig_filename; } @@ -5093,17 +5106,9 @@ See Info node `(elisp)Modification Time' for more details. */) filename = ENCODE_FILE (BVAR (b, filename)); - if (stat (SSDATA (filename), &st) == 0) - mtime = get_stat_mtime (&st); - else - { - /* If the file doesn't exist now and didn't exist before, - we say that it isn't modified, provided the error is a tame one. */ - int ns = (errno == ENOENT || errno == EACCES || errno == ENOTDIR - ? NONEXISTENT_MODTIME_NSECS - : UNKNOWN_MODTIME_NSECS); - EMACS_SET_SECS_NSECS (mtime, 0, ns); - } + mtime = (stat (SSDATA (filename), &st) == 0 + ? get_stat_mtime (&st) + : special_mtime (errno)); if ((EMACS_TIME_EQ (mtime, b->modtime) /* If both exist, accept them if they are off by one second. */ || (EMACS_TIME_VALID_P (mtime) && EMACS_TIME_VALID_P (b->modtime) -- 2.39.2