Chromium Code Reviews| 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 "bin/directory.h" | 5 #include "bin/directory.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 | 9 |
| 10 #include "bin/platform.h" | 10 #include "bin/platform.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 DWORD attributes = find_file_data->dwFileAttributes; | 226 DWORD attributes = find_file_data->dwFileAttributes; |
| 227 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { | 227 if ((attributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { |
| 228 return DeleteDir(find_file_data->cFileName, path, path_length); | 228 return DeleteDir(find_file_data->cFileName, path, path_length); |
| 229 } else { | 229 } else { |
| 230 return DeleteFile(find_file_data->cFileName, path, path_length); | 230 return DeleteFile(find_file_data->cFileName, path, path_length); |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 | 234 |
| 235 static bool DeleteRecursively(const char* dir_name) { | 235 static bool DeleteRecursively(const char* dir_name) { |
| 236 // If the directory is a junction, it's pointing to some other place in the | |
| 237 // filesystem that we do not want to recurse into. | |
| 238 DWORD attributes = GetFileAttributes(dir_name); | |
| 239 if ((attributes != INVALID_FILE_ATTRIBUTES) && | |
| 240 (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0) { | |
| 241 printf("%s junction\n", dir_name); | |
|
Søren Gjesse
2012/08/17 07:07:37
Please remove debug print.
Mads Ager (google)
2012/08/17 07:08:46
Remove debug printing.
Bob Nystrom
2012/08/20 23:24:32
Done.
| |
| 242 // Just delete the junction itself. | |
| 243 return RemoveDirectory(dir_name) != 0; | |
| 244 } | |
| 245 | |
| 236 // Compute full path for the directory currently being deleted. The | 246 // Compute full path for the directory currently being deleted. The |
| 237 // path buffer will be used to construct the current path in the | 247 // path buffer will be used to construct the current path in the |
| 238 // recursive traversal. path_length does not always equal | 248 // recursive traversal. path_length does not always equal |
| 239 // strlen(path) but indicates the current prefix of path that is the | 249 // strlen(path) but indicates the current prefix of path that is the |
| 240 // path of the current directory in the traversal. | 250 // path of the current directory in the traversal. |
| 241 char* path = static_cast<char*>(malloc(MAX_PATH)); | 251 char* path = static_cast<char*>(malloc(MAX_PATH)); |
| 242 int path_length = 0; | 252 int path_length = 0; |
| 243 bool valid = ComputeFullSearchPath(dir_name, path, &path_length); | 253 bool valid = ComputeFullSearchPath(dir_name, path, &path_length); |
| 244 if (!valid) { | 254 if (!valid) { |
| 245 free(path); | 255 free(path); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 // MoveFile does not allow replacing exising directories. Therefore, | 401 // MoveFile does not allow replacing exising directories. Therefore, |
| 392 // if the new_path is currently a directory we need to delete it | 402 // if the new_path is currently a directory we need to delete it |
| 393 // first. | 403 // first. |
| 394 if (new_exists == EXISTS) { | 404 if (new_exists == EXISTS) { |
| 395 bool success = DeleteRecursively(new_path); | 405 bool success = DeleteRecursively(new_path); |
| 396 if (!success) return false; | 406 if (!success) return false; |
| 397 } | 407 } |
| 398 DWORD flags = MOVEFILE_WRITE_THROUGH; | 408 DWORD flags = MOVEFILE_WRITE_THROUGH; |
| 399 return (MoveFileEx(path, new_path, flags) != 0); | 409 return (MoveFileEx(path, new_path, flags) != 0); |
| 400 } | 410 } |
| OLD | NEW |