Chromium Code Reviews| Index: runtime/bin/file_win.cc |
| diff --git a/runtime/bin/file_win.cc b/runtime/bin/file_win.cc |
| index 3780fca056c2adf2f827ef271da4ae4ecf839228..f82d15251115b101bad364abb2f959a1509c2d2c 100644 |
| --- a/runtime/bin/file_win.cc |
| +++ b/runtime/bin/file_win.cc |
| @@ -7,6 +7,7 @@ |
| #include "bin/file.h" |
| +#include <errno.h> // NOLINT |
|
Søren Gjesse
2013/04/08 07:21:18
No need for this
Anders Johnsen
2013/04/08 07:44:04
Done.
|
| #include <fcntl.h> // NOLINT |
| #include <io.h> // NOLINT |
| #include <stdio.h> // NOLINT |
| @@ -259,19 +260,25 @@ 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; |
| + result = (RemoveDirectoryW(system_name) != 0); |
| } else { |
| - int status = _wremove(system_name); |
| - free(const_cast<wchar_t*>(system_name)); |
| - if (status == -1) { |
| - return false; |
| - } |
| - return true; |
| + errno = EINVAL; |
|
Søren Gjesse
2013/04/08 07:21:18
SetLastError
Anders Johnsen
2013/04/08 07:44:04
Done.
|
| } |
| + free(const_cast<wchar_t*>(system_name)); |
| + return result; |
| } |
| @@ -480,15 +487,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 +502,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; |
| } |