Improve copy-file diagnostics on MS-Windows.
authorEli Zaretskii <eliz@gnu.org>
Sat, 29 Dec 2012 17:47:39 +0000 (19:47 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 29 Dec 2012 17:47:39 +0000 (19:47 +0200)
 src/fileio.c (Fcopy_file) [WINDOWSNT]: Improve diagnostics when CopyFile
 fails by looking at what GetLastError returns.

src/ChangeLog
src/fileio.c

index f40f936..e95df2b 100644 (file)
@@ -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.
index 241775a..0e63e3f 100644 (file)
@@ -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))
     {