Skip to content

Commit 9462778

Browse files
committed
merge revision(s) 49634,49658,49663: [Backport ruby#10865]
* 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 ruby#10865] * win32/win32.c (different_device_p): compare by volume serial numbers, not by path names. numbers, not by path names. [ruby-core:68162] [Bug ruby#10865] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@50290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 99fdb0a commit 9462778

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
Mon Apr 13 17:09:06 2015 Nobuyoshi Nakada <[email protected]>
2+
3+
* win32/win32.c (different_device_p): compare by volume serial
4+
numbers, not by path names. [ruby-core:68162] [Bug #10865]
5+
6+
Mon Apr 13 17:09:06 2015 Nobuyoshi Nakada <[email protected]>
7+
8+
* win32/win32.c (wrename): return EXDEV if moving a directory to
9+
another drive, since MoveFileExW does not set proper error code.
10+
[ruby-core:68162] [Bug #10865]
11+
112
Mon Apr 13 17:02:25 2015 Scott Francis <[email protected]>
213

314
* thread_pthread.c (reserve_stack): fix intermittent SIGBUS on

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.5"
22
#define RUBY_RELEASE_DATE "2015-04-13"
3-
#define RUBY_PATCHLEVEL 333
3+
#define RUBY_PATCHLEVEL 334
44

55
#define RUBY_RELEASE_YEAR 2015
66
#define RUBY_RELEASE_MONTH 4

win32/win32.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4673,6 +4673,31 @@ rb_w32_getenv(const char *name)
46734673
return w32_getenv(name, CP_ACP);
46744674
}
46754675

4676+
/* License: Ruby's */
4677+
static DWORD
4678+
get_volume_serial_number(const WCHAR *path)
4679+
{
4680+
const DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
4681+
const DWORD creation = OPEN_EXISTING;
4682+
const DWORD flags = FILE_FLAG_BACKUP_SEMANTICS;
4683+
BY_HANDLE_FILE_INFORMATION st = {0};
4684+
HANDLE h = CreateFileW(path, 0, share_mode, NULL, creation, flags, NULL);
4685+
BOOL ret;
4686+
4687+
if (h == INVALID_HANDLE_VALUE) return 0;
4688+
ret = GetFileInformationByHandle(h, &st);
4689+
CloseHandle(h);
4690+
if (!ret) return 0;
4691+
return st.dwVolumeSerialNumber;
4692+
}
4693+
4694+
/* License: Ruby's */
4695+
static int
4696+
different_device_p(const WCHAR *oldpath, const WCHAR *newpath)
4697+
{
4698+
return get_volume_serial_number(oldpath) != get_volume_serial_number(newpath);
4699+
}
4700+
46764701
/* License: Artistic or GPL */
46774702
static int
46784703
wrename(const WCHAR *oldpath, const WCHAR *newpath)
@@ -4696,8 +4721,14 @@ wrename(const WCHAR *oldpath, const WCHAR *newpath)
46964721
if (!MoveFileExW(oldpath, newpath, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED))
46974722
res = -1;
46984723

4699-
if (res)
4700-
errno = map_errno(GetLastError());
4724+
if (res) {
4725+
DWORD e = GetLastError();
4726+
if ((e == ERROR_ACCESS_DENIED) && (oldatts & FILE_ATTRIBUTE_DIRECTORY) &&
4727+
different_device_p(oldpath, newpath))
4728+
errno = EXDEV;
4729+
else
4730+
errno = map_errno(e);
4731+
}
47014732
else
47024733
SetFileAttributesW(newpath, oldatts);
47034734
});

0 commit comments

Comments
 (0)