emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r106818: Fix bug #10284 with renaming


From: Eli Zaretskii
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r106818: Fix bug #10284 with renaming a directory on MS-Windows.
Date: Sat, 07 Jan 2012 11:50:57 +0200
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 106818
fixes bug(s): http://debbugs.gnu.org/10284
author: LynX <address@hidden>
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Sat 2012-01-07 11:50:57 +0200
message:
  Fix bug #10284 with renaming a directory on MS-Windows.
  
   src/w32.c (sys_rename): Report EXDEV when rename of a directory
   fails because the target is on another logical disk.  (Bug#10284)
modified:
  src/ChangeLog
  src/w32.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-01-07 07:02:06 +0000
+++ b/src/ChangeLog     2012-01-07 09:50:57 +0000
@@ -1,3 +1,8 @@
+2012-01-07  LynX  <address@hidden>  (tiny change)
+
+       * w32.c (sys_rename): Report EXDEV when rename of a directory
+       fails because the target is on another logical disk.  (Bug#10284)
+
 2012-01-07  David Benjamin  <address@hidden>  (tiny change)
 
        * xterm.c (x_embed_request_focus): New function.

=== modified file 'src/w32.c'
--- a/src/w32.c 2012-01-05 09:46:05 +0000
+++ b/src/w32.c 2012-01-07 09:50:57 +0000
@@ -2894,6 +2894,8 @@
 {
   BOOL result;
   char temp[MAX_PATH];
+  int newname_dev;
+  int oldname_dev;
 
   /* MoveFile on Windows 95 doesn't correctly change the short file name
      alias in a number of circumstances (it is not easy to predict when
@@ -2910,6 +2912,9 @@
 
   strcpy (temp, map_w32_filename (oldname, NULL));
 
+  /* volume_info is set indirectly by map_w32_filename.  */
+  oldname_dev = volume_info.serialnum;
+
   if (os_subtype == OS_WIN95)
     {
       char * o;
@@ -2953,13 +2958,38 @@
      all the permutations of shared or subst'd drives, etc.)  */
 
   newname = map_w32_filename (newname, NULL);
+
+  /* volume_info is set indirectly by map_w32_filename.  */
+  newname_dev = volume_info.serialnum;
+
   result = rename (temp, newname);
 
-  if (result < 0
-      && errno == EEXIST
-      && _chmod (newname, 0666) == 0
-      && _unlink (newname) == 0)
-    result = rename (temp, newname);
+  if (result < 0)
+    {
+
+      if (errno == EACCES
+         && newname_dev != oldname_dev)
+       {
+         /* The implementation of `rename' on Windows does not return
+            errno = EXDEV when you are moving a directory to a
+            different storage device (ex. logical disk).  It returns
+            EACCES instead.  So here we handle such situations and
+            return EXDEV.  */
+         DWORD attributes;
+
+         if ((attributes = GetFileAttributes (temp)) != -1
+             && attributes & FILE_ATTRIBUTE_DIRECTORY)
+           errno = EXDEV;
+       }
+      else if (errno == EEXIST)
+       {
+         if (_chmod (newname, 0666) != 0)
+           return result;
+         if (_unlink (newname) != 0)
+           return result;
+         result = rename (temp, newname);
+       }
+    }
 
   return result;
 }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]