aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/fileio.c43
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 @@
12012-07-03 Paul Eggert <eggert@cs.ucla.edu>
2
3 * fileio.c: Improve handling of file time marker. (Bug#11852)
4 (special_mtime): New function.
5 (Finsert_file_contents, Fverify_visited_file_modtime):
6 Use it to set special mtime values consistently.
7
12012-07-03 Andreas Schwab <schwab@linux-m68k.org> 82012-07-03 Andreas Schwab <schwab@linux-m68k.org>
2 9
3 * fileio.c (Finsert_file_contents): Properly handle st_mtime 10 * 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)
3215 return lseek (fd, offset, whence); 3215 return lseek (fd, offset, whence);
3216} 3216}
3217 3217
3218/* Return a special mtime value indicating the error number ERRNUM. */
3219static EMACS_TIME
3220special_mtime (int errnum)
3221{
3222 EMACS_TIME t;
3223 int ns = (errno == ENOENT || errno == EACCES || errno == ENOTDIR
3224 ? NONEXISTENT_MODTIME_NSECS
3225 : UNKNOWN_MODTIME_NSECS);
3226 EMACS_SET_SECS_NSECS (t, 0, ns);
3227 return t;
3228}
3218 3229
3219DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, 3230DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents,
3220 1, 5, 0, 3231 1, 5, 0,
@@ -3242,6 +3253,8 @@ variable `last-coding-system-used' to the coding system actually used. */)
3242 (Lisp_Object filename, Lisp_Object visit, Lisp_Object beg, Lisp_Object end, Lisp_Object replace) 3253 (Lisp_Object filename, Lisp_Object visit, Lisp_Object beg, Lisp_Object end, Lisp_Object replace)
3243{ 3254{
3244 struct stat st; 3255 struct stat st;
3256 int file_status;
3257 EMACS_TIME mtime;
3245 register int fd; 3258 register int fd;
3246 ptrdiff_t inserted = 0; 3259 ptrdiff_t inserted = 0;
3247 int nochange = 0; 3260 int nochange = 0;
@@ -3310,19 +3323,22 @@ variable `last-coding-system-used' to the coding system actually used. */)
3310 3323
3311 /* Tell stat to use expensive method to get accurate info. */ 3324 /* Tell stat to use expensive method to get accurate info. */
3312 Vw32_get_true_file_attributes = Qt; 3325 Vw32_get_true_file_attributes = Qt;
3313 total = stat (SSDATA (filename), &st); 3326 file_status = stat (SSDATA (filename), &st);
3314 Vw32_get_true_file_attributes = tem; 3327 Vw32_get_true_file_attributes = tem;
3315 } 3328 }
3316 if (total < 0)
3317#else 3329#else
3318 if (stat (SSDATA (filename), &st) < 0) 3330 file_status = stat (SSDATA (filename), &st);
3319#endif /* WINDOWSNT */ 3331#endif /* WINDOWSNT */
3332
3333 if (file_status == 0)
3334 mtime = get_stat_mtime (&st);
3335 else
3320 { 3336 {
3321 badopen: 3337 badopen:
3322 save_errno = errno; 3338 save_errno = errno;
3323 if (NILP (visit)) 3339 if (NILP (visit))
3324 report_file_error ("Opening input file", Fcons (orig_filename, Qnil)); 3340 report_file_error ("Opening input file", Fcons (orig_filename, Qnil));
3325 st.st_mtime = -1; 3341 mtime = special_mtime (save_errno);
3326 st.st_size = -1; 3342 st.st_size = -1;
3327 how_much = 0; 3343 how_much = 0;
3328 if (!NILP (Vcoding_system_for_read)) 3344 if (!NILP (Vcoding_system_for_read))
@@ -4193,10 +4209,7 @@ variable `last-coding-system-used' to the coding system actually used. */)
4193 4209
4194 if (NILP (handler)) 4210 if (NILP (handler))
4195 { 4211 {
4196 if (st.st_mtime == -1) 4212 current_buffer->modtime = mtime;
4197 EMACS_SET_INVALID_TIME (current_buffer->modtime);
4198 else
4199 current_buffer->modtime = get_stat_mtime (&st);
4200 current_buffer->modtime_size = st.st_size; 4213 current_buffer->modtime_size = st.st_size;
4201 BVAR (current_buffer, filename) = orig_filename; 4214 BVAR (current_buffer, filename) = orig_filename;
4202 } 4215 }
@@ -5093,17 +5106,9 @@ See Info node `(elisp)Modification Time' for more details. */)
5093 5106
5094 filename = ENCODE_FILE (BVAR (b, filename)); 5107 filename = ENCODE_FILE (BVAR (b, filename));
5095 5108
5096 if (stat (SSDATA (filename), &st) == 0) 5109 mtime = (stat (SSDATA (filename), &st) == 0
5097 mtime = get_stat_mtime (&st); 5110 ? get_stat_mtime (&st)
5098 else 5111 : special_mtime (errno));
5099 {
5100 /* If the file doesn't exist now and didn't exist before,
5101 we say that it isn't modified, provided the error is a tame one. */
5102 int ns = (errno == ENOENT || errno == EACCES || errno == ENOTDIR
5103 ? NONEXISTENT_MODTIME_NSECS
5104 : UNKNOWN_MODTIME_NSECS);
5105 EMACS_SET_SECS_NSECS (mtime, 0, ns);
5106 }
5107 if ((EMACS_TIME_EQ (mtime, b->modtime) 5112 if ((EMACS_TIME_EQ (mtime, b->modtime)
5108 /* If both exist, accept them if they are off by one second. */ 5113 /* If both exist, accept them if they are off by one second. */
5109 || (EMACS_TIME_VALID_P (mtime) && EMACS_TIME_VALID_P (b->modtime) 5114 || (EMACS_TIME_VALID_P (mtime) && EMACS_TIME_VALID_P (b->modtime)