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

Unified Diff: runtime/bin/directory_win.cc

Issue 10867003: When a directory contains read-only files, try to make them writable when recursively deleting on W… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 063f119c9e0baad4ea33475054b3cfbc4b04619a..76044f137a536fb0636017c413d0df44ffdff1ed 100644
--- a/runtime/bin/directory_win.cc
+++ b/runtime/bin/directory_win.cc
@@ -198,7 +198,30 @@ static bool DeleteFile(char* file_name,
if (written != strlen(file_name)) {
return false;
}
- return (DeleteFile(path) != 0);
+
+ if (DeleteFile(path) != 0) {
+ return true;
+ }
+
+ // If we failed because the file is read-only, make it writeable and try
+ // again. This mirrors Linux/Mac where a directory containing read-only files
+ // can still be recursively deleted.
+ if (GetLastError() == ERROR_ACCESS_DENIED) {
+ DWORD attributes = GetFileAttributes(path);
+ if (attributes == INVALID_FILE_ATTRIBUTES) {
+ return false;
+ }
+
+ if ((attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY) {
+ attributes &= ~FILE_ATTRIBUTE_READONLY;
+
+ if (SetFileAttributes(path, attributes) == 0) {
+ return false;
+ }
+
+ return DeleteFile(path) != 0;
+ }
+ }
}
@@ -224,6 +247,7 @@ static bool DeleteEntry(LPWIN32_FIND_DATA find_file_data,
char* path,
int path_length) {
DWORD attributes = find_file_data->dwFileAttributes;
+
if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
return DeleteDir(find_file_data->cFileName, path, path_length);
} else {
« 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