From: Jason Rumney Date: Sat, 9 Mar 2002 00:38:54 +0000 (+0000) Subject: (Fcopy_file) [WINDOWS_NT]: Ensure file is not X-Git-Tag: ttn-vms-21-2-B4~16268 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ad497129bafbe28df203d8a5bc309daa6d2ae646;p=emacs.git (Fcopy_file) [WINDOWS_NT]: Ensure file is not read-only when setting modified time. --- diff --git a/src/ChangeLog b/src/ChangeLog index 2864d8f1296..5ae6ce6ebf5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2002-03-09 Jason Rumney + + * fileio.c (Fcopy_file) [WINDOWS_NT]: Ensure file is not + read-only when setting modified time. + 2002-03-08 Gerd Moellmann * xdisp.c (move_it_vertically_backward): At the end of the diff --git a/src/fileio.c b/src/fileio.c index d328a2d3636..bb39f2a153b 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2409,12 +2409,25 @@ A prefix arg makes KEEP-TIME non-nil. */) else if (NILP (keep_time)) { EMACS_TIME now; + DWORD attributes; + char * filename; + EMACS_GET_TIME (now); - if (set_file_times (XSTRING (encoded_newname)->data, - now, now)) - Fsignal (Qfile_date_error, - Fcons (build_string ("Cannot set file date"), - Fcons (newname, Qnil))); + filename = XSTRING (encoded_newname)->data; + + /* Ensure file is writable while its modified time is set. */ + attributes = GetFileAttributes (filename); + SetFileAttributes (filename, attributes ^ FILE_ATTRIBUTE_READONLY); + if (set_file_times (filename, now, now)) + { + /* Restore original attributes. */ + SetFileAttributes (filename, attributes); + Fsignal (Qfile_date_error, + Fcons (build_string ("Cannot set file date"), + Fcons (newname, Qnil))); + } + /* Restore original attributes. */ + SetFileAttributes (filename, attributes); } #else /* not WINDOWSNT */ ifd = emacs_open (XSTRING (encoded_file)->data, O_RDONLY, 0);