From: Eli Zaretskii Date: Sat, 29 Dec 2012 17:47:39 +0000 (+0200) Subject: Improve copy-file diagnostics on MS-Windows. X-Git-Tag: emacs-24.3.90~173^2~7^2~448 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8d23a331207808396cf7359314f506158900f024;p=emacs.git Improve copy-file diagnostics on MS-Windows. src/fileio.c (Fcopy_file) [WINDOWSNT]: Improve diagnostics when CopyFile fails by looking at what GetLastError returns. --- diff --git a/src/ChangeLog b/src/ChangeLog index f40f936d13a..e95df2b8953 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -3,6 +3,7 @@ * fileio.c (Fset_file_selinux_context, Fset_file_acl): Return t if file's SELinux context or ACLs successfully set, nil otherwise. (Bug#13298) + (Fcopy_file) [WINDOWSNT]: Improve diagnostics when CopyFile fails. * w32proc.c (reader_thread): Avoid passing NULL handles to SetEvent and WaitForSingleObject. diff --git a/src/fileio.c b/src/fileio.c index 241775abec1..0e63e3f18d9 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2029,7 +2029,15 @@ entries (depending on how Emacs was built). */) if (!CopyFile (SDATA (encoded_file), SDATA (encoded_newname), FALSE)) - report_file_error ("Copying file", Fcons (file, Fcons (newname, Qnil))); + { + /* CopyFile doesn't set errno when it fails. By far the most + "popular" reason is that the target is read-only. */ + if (GetLastError () == 5) + errno = EACCES; + else + errno = EPERM; + report_file_error ("Copying file", Fcons (file, Fcons (newname, Qnil))); + } /* CopyFile retains the timestamp by default. */ else if (NILP (keep_time)) {