[前][次][番号順一覧][スレッド一覧]

ruby-changes:37553

From: nobu <ko1@a...>
Date: Wed, 18 Feb 2015 10:49:14 +0900 (JST)
Subject: [ruby-changes:37553] nobu:r49634 (trunk): win32.c: EXDEV for directory

nobu	2015-02-18 10:48:58 +0900 (Wed, 18 Feb 2015)

  New Revision: 49634

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49634

  Log:
    win32.c: EXDEV for directory
    
    * win32/win32.c (wrename): return EXDEV if moving a directory to
      another drive, since MoveFileExW does not set proper error code.
      [ruby-core:68162] [Bug #10865]

  Modified files:
    trunk/ChangeLog
    trunk/win32/win32.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49633)
+++ ChangeLog	(revision 49634)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Feb 18 10:48:56 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/win32.c (wrename): return EXDEV if moving a directory to
+	  another drive, since MoveFileExW does not set proper error code.
+	  [ruby-core:68162] [Bug #10865]
+
 Wed Feb 18 03:13:52 2015  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych.rb: bump psych version.
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 49633)
+++ win32/win32.c	(revision 49634)
@@ -4701,6 +4701,31 @@ rb_w32_getenv(const char *name) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4701
     return w32_getenv(name, CP_ACP);
 }
 
+/* License: Ruby's */
+static int
+different_device_p(const WCHAR *oldpath, const WCHAR *newpath)
+{
+    WCHAR oldfullpath[_MAX_PATH], newfullpath[_MAX_PATH];
+    DWORD oldlen, newlen;
+
+    newlen = GetFullPathNameW(newpath, numberof(newfullpath), newfullpath, NULL);
+    if (newlen <= 1) return 0;
+    oldlen = GetFullPathNameW(oldpath, numberof(oldfullpath), oldfullpath, NULL);
+    if (oldlen <= 1) return 0;
+    if (newfullpath[1] == L':') {
+	if (oldfullpath[1] != L':') return 1;
+	return newfullpath[0] != oldfullpath[0];
+    }
+    if (newfullpath[0] != L'\\' || newfullpath[1] != L'\\') return 0;
+    if (oldfullpath[0] != L'\\' || oldfullpath[1] != L'\\') return 0;
+    if (!(newpath = wcschr(newfullpath+2, L'\\'))) return 0;
+    if (!(newpath = wcschr(newpath+1, L'\\'))) return 0;
+    if (!(oldpath = wcschr(oldfullpath+2, L'\\'))) return 0;
+    if (!(oldpath = wcschr(oldpath+1, L'\\'))) return 0;
+    if (newpath - newfullpath != oldpath - oldfullpath) return 1;
+    return wcsncmp(newfullpath, oldfullpath, oldpath - oldfullpath) != 0;
+}
+
 /* License: Artistic or GPL */
 static int
 wrename(const WCHAR *oldpath, const WCHAR *newpath)
@@ -4724,8 +4749,14 @@ wrename(const WCHAR *oldpath, const WCHA https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4749
 	if (!MoveFileExW(oldpath, newpath, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED))
 	    res = -1;
 
-	if (res)
-	    errno = map_errno(GetLastError());
+	if (res) {
+	    DWORD e = GetLastError();
+	    if ((e == ERROR_ACCESS_DENIED) && (oldatts & FILE_ATTRIBUTE_DIRECTORY) &&
+		different_device_p(oldpath, newpath))
+		errno = EXDEV;
+	    else
+		errno = map_errno(e);
+	}
 	else
 	    SetFileAttributesW(newpath, oldatts);
     });

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]