Commit dbeed9a6 authored by Paul Eggert's avatar 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.
parent 636334d6
2012-07-03 Paul Eggert <eggert@cs.ucla.edu>
* 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 <schwab@linux-m68k.org>
* fileio.c (Finsert_file_contents): Properly handle st_mtime
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment