| Index: runtime/bin/file_win.cc
|
| diff --git a/runtime/bin/file_win.cc b/runtime/bin/file_win.cc
|
| index 3780fca056c2adf2f827ef271da4ae4ecf839228..b8ee7d585b8634658ea1378f4f2607a4dc001113 100644
|
| --- a/runtime/bin/file_win.cc
|
| +++ b/runtime/bin/file_win.cc
|
| @@ -259,19 +259,23 @@ bool File::CreateLink(const char* utf8_name, const char* utf8_target) {
|
|
|
| bool File::Delete(const char* name) {
|
| const wchar_t* system_name = StringUtils::Utf8ToWide(name);
|
| + int status = _wremove(system_name);
|
| + free(const_cast<wchar_t*>(system_name));
|
| + return status != -1;
|
| +}
|
| +
|
| +
|
| +bool File::DeleteLink(const char* name) {
|
| + const wchar_t* system_name = StringUtils::Utf8ToWide(name);
|
| + bool result = false;
|
| DWORD attributes = GetFileAttributesW(system_name);
|
| if ((attributes != INVALID_FILE_ATTRIBUTES) &&
|
| (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
|
| // It's a junction(link), delete it.
|
| - return RemoveDirectoryW(system_name) != 0;
|
| - } else {
|
| - int status = _wremove(system_name);
|
| - free(const_cast<wchar_t*>(system_name));
|
| - if (status == -1) {
|
| - return false;
|
| - }
|
| - return true;
|
| + result = (RemoveDirectoryW(system_name) != 0);
|
| }
|
| + free(const_cast<wchar_t*>(system_name));
|
| + return result;
|
| }
|
|
|
|
|
| @@ -480,15 +484,11 @@ File::StdioHandleType File::GetStdioHandleType(int fd) {
|
|
|
| File::Type File::GetType(const char* pathname, bool follow_links) {
|
| const wchar_t* name = StringUtils::Utf8ToWide(pathname);
|
| - WIN32_FIND_DATAW file_data;
|
| - HANDLE find_handle = FindFirstFileW(name, &file_data);
|
| - if (find_handle == INVALID_HANDLE_VALUE) {
|
| - // TODO(whesse): Distinguish other errors from does not exist.
|
| - return File::kDoesNotExist;
|
| - }
|
| - FindClose(find_handle);
|
| - DWORD attributes = file_data.dwFileAttributes;
|
| - if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
|
| + DWORD attributes = GetFileAttributesW(name);
|
| + File::Type result = kIsFile;
|
| + if (attributes == INVALID_FILE_ATTRIBUTES) {
|
| + result = kDoesNotExist;
|
| + } else if ((attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
|
| if (follow_links) {
|
| HANDLE dir_handle = CreateFileW(
|
| name,
|
| @@ -499,26 +499,19 @@ File::Type File::GetType(const char* pathname, bool follow_links) {
|
| FILE_FLAG_BACKUP_SEMANTICS,
|
| NULL);
|
| if (dir_handle == INVALID_HANDLE_VALUE) {
|
| - // TODO(whesse): Distinguish other errors from does not exist.
|
| - return File::kDoesNotExist;
|
| + result = File::kIsLink;
|
| } else {
|
| CloseHandle(dir_handle);
|
| - return File::kIsDirectory;
|
| + result = File::kIsDirectory;
|
| }
|
| } else {
|
| - DWORD reparse_tag = file_data.dwReserved0;
|
| - if (reparse_tag == IO_REPARSE_TAG_SYMLINK ||
|
| - reparse_tag == IO_REPARSE_TAG_MOUNT_POINT) {
|
| - return File::kIsLink;
|
| - } else {
|
| - return File::kDoesNotExist;
|
| - }
|
| + result = kIsLink;
|
| }
|
| } else if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
|
| - return File::kIsDirectory;
|
| - } else {
|
| - return File::kIsFile;
|
| + result = kIsDirectory;
|
| }
|
| + free(const_cast<wchar_t*>(name));
|
| + return result;
|
| }
|
|
|
|
|
|
|