win32.c: get attributes and VSN at once
* win32/win32.c (wrename): get attributes and VSN at once for each path names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f64d6357b6
commit
a2da0f7e42
@ -4979,24 +4979,22 @@ rb_w32_getenv(const char *name)
|
|||||||
|
|
||||||
/* License: Ruby's */
|
/* License: Ruby's */
|
||||||
static DWORD
|
static DWORD
|
||||||
get_volume_serial_number(const WCHAR *path)
|
get_attr_vsn(const WCHAR *path, DWORD *atts, DWORD *vsn)
|
||||||
{
|
{
|
||||||
BY_HANDLE_FILE_INFORMATION st = {0};
|
BY_HANDLE_FILE_INFORMATION st = {0};
|
||||||
HANDLE h = open_special(path, 0, 0);
|
DWORD e = 0;
|
||||||
BOOL ret;
|
HANDLE h = open_special(path, 0, FILE_FLAG_OPEN_REPARSE_POINT);
|
||||||
|
|
||||||
if (h == INVALID_HANDLE_VALUE) return 0;
|
if (h == INVALID_HANDLE_VALUE) return GetLastError();
|
||||||
ret = GetFileInformationByHandle(h, &st);
|
if (!GetFileInformationByHandle(h, &st)) {
|
||||||
|
e = GetLastError();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*atts = st.dwFileAttributes;
|
||||||
|
*vsn = st.dwVolumeSerialNumber;
|
||||||
|
}
|
||||||
CloseHandle(h);
|
CloseHandle(h);
|
||||||
if (!ret) return 0;
|
return e;
|
||||||
return st.dwVolumeSerialNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* License: Ruby's */
|
|
||||||
static int
|
|
||||||
different_device_p(const WCHAR *oldpath, const WCHAR *newpath)
|
|
||||||
{
|
|
||||||
return get_volume_serial_number(oldpath) != get_volume_serial_number(newpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* License: Artistic or GPL */
|
/* License: Artistic or GPL */
|
||||||
@ -5004,20 +5002,18 @@ static int
|
|||||||
wrename(const WCHAR *oldpath, const WCHAR *newpath)
|
wrename(const WCHAR *oldpath, const WCHAR *newpath)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int oldatts;
|
int oldatts = -1, newatts = -1;
|
||||||
int newatts;
|
DWORD oldvsn = 0, newvsn = 0, e;
|
||||||
|
|
||||||
oldatts = GetFileAttributesW(oldpath);
|
e = get_attr_vsn(oldpath, &oldatts, &oldvsn);
|
||||||
newatts = GetFileAttributesW(newpath);
|
if (e) {
|
||||||
|
errno = map_errno(e);
|
||||||
if (oldatts == -1) {
|
|
||||||
errno = map_errno(GetLastError());
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (oldatts & FILE_ATTRIBUTE_REPARSE_POINT) {
|
if (oldatts & FILE_ATTRIBUTE_REPARSE_POINT) {
|
||||||
HANDLE fh = open_special(oldpath, 0, 0);
|
HANDLE fh = open_special(oldpath, 0, 0);
|
||||||
if (fh == INVALID_HANDLE_VALUE) {
|
if (fh == INVALID_HANDLE_VALUE) {
|
||||||
DWORD e = GetLastError();
|
e = GetLastError();
|
||||||
if (e == ERROR_CANT_RESOLVE_FILENAME) {
|
if (e == ERROR_CANT_RESOLVE_FILENAME) {
|
||||||
errno = ELOOP;
|
errno = ELOOP;
|
||||||
return -1;
|
return -1;
|
||||||
@ -5025,6 +5021,7 @@ wrename(const WCHAR *oldpath, const WCHAR *newpath)
|
|||||||
}
|
}
|
||||||
CloseHandle(fh);
|
CloseHandle(fh);
|
||||||
}
|
}
|
||||||
|
get_attr_vsn(newpath, &newatts, &newvsn);
|
||||||
|
|
||||||
RUBY_CRITICAL({
|
RUBY_CRITICAL({
|
||||||
if (newatts != -1 && newatts & FILE_ATTRIBUTE_READONLY)
|
if (newatts != -1 && newatts & FILE_ATTRIBUTE_READONLY)
|
||||||
@ -5036,7 +5033,7 @@ wrename(const WCHAR *oldpath, const WCHAR *newpath)
|
|||||||
if (res) {
|
if (res) {
|
||||||
DWORD e = GetLastError();
|
DWORD e = GetLastError();
|
||||||
if ((e == ERROR_ACCESS_DENIED) && (oldatts & FILE_ATTRIBUTE_DIRECTORY) &&
|
if ((e == ERROR_ACCESS_DENIED) && (oldatts & FILE_ATTRIBUTE_DIRECTORY) &&
|
||||||
different_device_p(oldpath, newpath))
|
oldvsn != newvsn)
|
||||||
errno = EXDEV;
|
errno = EXDEV;
|
||||||
else
|
else
|
||||||
errno = map_errno(e);
|
errno = map_errno(e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user