+2010-04-13 Stefan Monnier <monnier@iro.umontreal.ca>
+
+ Try to detect file modification within the same second.
+ * buffer.h (struct buffer): New field modtime_size.
+ * buffer.c (reset_buffer): Initialize it.
+ * fileio.c (Finsert_file_contents, Fwrite_region): Set it.
+ (Fverify_visited_file_modtime): Check it.
+ (Fclear_visited_file_modtime, Fset_visited_file_modtime): Clear it.
+ (Fset_visited_file_modtime): Set (or clear) it.
+
2010-04-12 Stefan Monnier <monnier@iro.umontreal.ca>
* process.c (status_notify): Remove unused var `ro'.
0 means visited file modtime unknown; in no case complain
about any mismatch on next save attempt. */
int modtime;
+ /* Size of the file when modtime was set. This is used to detect the
+ case where the file grew while we were reading it, so the modtime
+ is still the same (since it's rounded up to seconds) but we're actually
+ not up-to-date. -1 means the size is unknown. Only meaningful if
+ modtime is actually set. */
+ EMACS_INT modtime_size;
/* The value of text->modiff at the last auto-save. */
int auto_save_modified;
/* The value of text->modiff at the last display error.
if (NILP (handler))
{
current_buffer->modtime = st.st_mtime;
+ current_buffer->modtime_size = st.st_size;
current_buffer->filename = orig_filename;
}
to avoid a "file has changed on disk" warning on
next attempt to save. */
if (visiting)
- current_buffer->modtime = st.st_mtime;
+ {
+ current_buffer->modtime = st.st_mtime;
+ current_buffer->modtime_size = st.st_size;
+ }
if (failure)
error ("IO error writing %s: %s", SDATA (filename),
else
st.st_mtime = 0;
}
- if (st.st_mtime == b->modtime
- /* If both are positive, accept them if they are off by one second. */
- || (st.st_mtime > 0 && b->modtime > 0
- && (st.st_mtime == b->modtime + 1
- || st.st_mtime == b->modtime - 1)))
+ if ((st.st_mtime == b->modtime
+ /* If both are positive, accept them if they are off by one second. */
+ || (st.st_mtime > 0 && b->modtime > 0
+ && (st.st_mtime == b->modtime + 1
+ || st.st_mtime == b->modtime - 1)))
+ && (st.st_size == b->modtime_size
+ || b->modtime_size < 0))
return Qt;
return Qnil;
}
()
{
current_buffer->modtime = 0;
+ current_buffer->modtime_size = -1;
return Qnil;
}
Lisp_Object time_list;
{
if (!NILP (time_list))
- current_buffer->modtime = cons_to_long (time_list);
+ {
+ current_buffer->modtime = cons_to_long (time_list);
+ current_buffer->modtime_size = -1;
+ }
else
{
register Lisp_Object filename;
filename = ENCODE_FILE (filename);
if (stat (SDATA (filename), &st) >= 0)
- current_buffer->modtime = st.st_mtime;
+ {
+ current_buffer->modtime = st.st_mtime;
+ current_buffer->modtime_size = st.st_size;
+ }
}
return Qnil;