Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Unified Diff: runtime/bin/directory_win.cc

Issue 276593005: Clean up recursive deletion on windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_win.cc
diff --git a/runtime/bin/directory_win.cc b/runtime/bin/directory_win.cc
index ecfa7e9a5a8fc1f0b9d487e9865fc11c04050cf6..e7cd89531b9f95f350647fefcebae308576d9107 100644
--- a/runtime/bin/directory_win.cc
+++ b/runtime/bin/directory_win.cc
@@ -302,32 +302,32 @@ static bool DeleteRecursively(PathBuffer* path) {
WIN32_FIND_DATAW find_file_data;
HANDLE find_handle = FindFirstFileW(path->AsStringW(), &find_file_data);
- // Adjust the path by removing the '*' used for the search.
- int path_length = path->length() - 1;
- path->Reset(path_length);
-
if (find_handle == INVALID_HANDLE_VALUE) {
return false;
}
+ // Adjust the path by removing the '*' used for the search.
+ int path_length = path->length() - 1;
+ path->Reset(path_length);
+
do {
if (!DeleteEntry(&find_file_data, path)) {
- DWORD last_error = GetLastError();
- FindClose(find_handle);
- SetLastError(last_error);
- return false;
+ break;
}
path->Reset(path_length); // DeleteEntry adds to the path.
} while (FindNextFileW(find_handle, &find_file_data) != 0);
- path->Reset(path_length - 1); // Drop the "\" from the end of the path.
- if ((GetLastError() != ERROR_NO_MORE_FILES) ||
- (FindClose(find_handle) == 0) ||
- (RemoveDirectoryW(path->AsStringW()) == 0)) {
+ DWORD last_error = GetLastError();
+ // Always close handle.
+ FindClose(find_handle);
+ if (last_error != ERROR_NO_MORE_FILES) {
+ // Unexpected error, set and return.
+ SetLastError(last_error);
return false;
}
-
- return true;
+ // All content deleted succesfully, try to delete directory.
+ path->Reset(path_length - 1); // Drop the "\" from the end of the path.
+ return RemoveDirectoryW(path->AsStringW()) != 0;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698