summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--win32/win32.c35
2 files changed, 39 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 98440aeb53..6bcf508834 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Feb 18 10:48:56 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@tenderlovemaking.com>
* ext/psych/lib/psych.rb: bump psych version.
diff --git a/win32/win32.c b/win32/win32.c
index 34d42b0ded..023d1a82f8 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -4701,6 +4701,31 @@ rb_w32_getenv(const char *name)
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 WCHAR *newpath)
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);
});