| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
| 7 | 7 |
| 8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
| 9 #include "bin/file.h" | 9 #include "bin/file.h" |
| 10 #include "bin/utils.h" | 10 #include "bin/utils.h" |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 // If it's a file, remove it directly. | 295 // If it's a file, remove it directly. |
| 296 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { | 296 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { |
| 297 return DeleteFile(L"", path); | 297 return DeleteFile(L"", path); |
| 298 } | 298 } |
| 299 | 299 |
| 300 if (!path->AddW(L"\\*")) return false; | 300 if (!path->AddW(L"\\*")) return false; |
| 301 | 301 |
| 302 WIN32_FIND_DATAW find_file_data; | 302 WIN32_FIND_DATAW find_file_data; |
| 303 HANDLE find_handle = FindFirstFileW(path->AsStringW(), &find_file_data); | 303 HANDLE find_handle = FindFirstFileW(path->AsStringW(), &find_file_data); |
| 304 | 304 |
| 305 if (find_handle == INVALID_HANDLE_VALUE) { |
| 306 return false; |
| 307 } |
| 308 |
| 305 // Adjust the path by removing the '*' used for the search. | 309 // Adjust the path by removing the '*' used for the search. |
| 306 int path_length = path->length() - 1; | 310 int path_length = path->length() - 1; |
| 307 path->Reset(path_length); | 311 path->Reset(path_length); |
| 308 | 312 |
| 309 if (find_handle == INVALID_HANDLE_VALUE) { | |
| 310 return false; | |
| 311 } | |
| 312 | |
| 313 do { | 313 do { |
| 314 if (!DeleteEntry(&find_file_data, path)) { | 314 if (!DeleteEntry(&find_file_data, path)) { |
| 315 DWORD last_error = GetLastError(); | 315 break; |
| 316 FindClose(find_handle); | |
| 317 SetLastError(last_error); | |
| 318 return false; | |
| 319 } | 316 } |
| 320 path->Reset(path_length); // DeleteEntry adds to the path. | 317 path->Reset(path_length); // DeleteEntry adds to the path. |
| 321 } while (FindNextFileW(find_handle, &find_file_data) != 0); | 318 } while (FindNextFileW(find_handle, &find_file_data) != 0); |
| 322 | 319 |
| 323 path->Reset(path_length - 1); // Drop the "\" from the end of the path. | 320 DWORD last_error = GetLastError(); |
| 324 if ((GetLastError() != ERROR_NO_MORE_FILES) || | 321 // Always close handle. |
| 325 (FindClose(find_handle) == 0) || | 322 FindClose(find_handle); |
| 326 (RemoveDirectoryW(path->AsStringW()) == 0)) { | 323 if (last_error != ERROR_NO_MORE_FILES) { |
| 324 // Unexpected error, set and return. |
| 325 SetLastError(last_error); |
| 327 return false; | 326 return false; |
| 328 } | 327 } |
| 329 | 328 // All content deleted succesfully, try to delete directory. |
| 330 return true; | 329 path->Reset(path_length - 1); // Drop the "\" from the end of the path. |
| 330 return RemoveDirectoryW(path->AsStringW()) != 0; |
| 331 } | 331 } |
| 332 | 332 |
| 333 | 333 |
| 334 static Directory::ExistsResult ExistsHelper(const wchar_t* dir_name) { | 334 static Directory::ExistsResult ExistsHelper(const wchar_t* dir_name) { |
| 335 DWORD attributes = GetFileAttributesW(dir_name); | 335 DWORD attributes = GetFileAttributesW(dir_name); |
| 336 if (attributes == INVALID_FILE_ATTRIBUTES) { | 336 if (attributes == INVALID_FILE_ATTRIBUTES) { |
| 337 DWORD last_error = GetLastError(); | 337 DWORD last_error = GetLastError(); |
| 338 if (last_error == ERROR_FILE_NOT_FOUND || | 338 if (last_error == ERROR_FILE_NOT_FOUND || |
| 339 last_error == ERROR_PATH_NOT_FOUND) { | 339 last_error == ERROR_PATH_NOT_FOUND) { |
| 340 return Directory::DOES_NOT_EXIST; | 340 return Directory::DOES_NOT_EXIST; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 MoveFileExW(system_path, system_new_path, flags); | 477 MoveFileExW(system_path, system_new_path, flags); |
| 478 free(const_cast<wchar_t*>(system_path)); | 478 free(const_cast<wchar_t*>(system_path)); |
| 479 free(const_cast<wchar_t*>(system_new_path)); | 479 free(const_cast<wchar_t*>(system_new_path)); |
| 480 return (move_status != 0); | 480 return (move_status != 0); |
| 481 } | 481 } |
| 482 | 482 |
| 483 } // namespace bin | 483 } // namespace bin |
| 484 } // namespace dart | 484 } // namespace dart |
| 485 | 485 |
| 486 #endif // defined(TARGET_OS_WINDOWS) | 486 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |