зеркало из https://github.com/github/ruby.git
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
df030b029f
Коммит
cc7e5eb7d9
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче