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_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
9 | 9 |
10 #include <dirent.h> // NOLINT | 10 #include <dirent.h> // NOLINT |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 return path->Add(dir_name) && DeleteRecursively(path); | 232 return path->Add(dir_name) && DeleteRecursively(path); |
233 } | 233 } |
234 | 234 |
235 | 235 |
236 static bool DeleteRecursively(PathBuffer* path) { | 236 static bool DeleteRecursively(PathBuffer* path) { |
237 // Do not recurse into links for deletion. Instead delete the link. | 237 // Do not recurse into links for deletion. Instead delete the link. |
238 struct stat st; | 238 struct stat st; |
239 if (TEMP_FAILURE_RETRY(lstat(path->data, &st)) == -1) { | 239 if (TEMP_FAILURE_RETRY(lstat(path->data, &st)) == -1) { |
240 return false; | 240 return false; |
241 } else if (S_ISLNK(st.st_mode)) { | 241 } else if (S_ISLNK(st.st_mode)) { |
242 return (remove(path->data) == 0); | 242 if (TEMP_FAILURE_RETRY(stat(path->data, &st)) == -1) { |
| 243 return false; |
| 244 } else if (S_ISDIR(st.st_mode)) { |
| 245 return (unlink(path->data) == 0); |
| 246 } |
243 } | 247 } |
244 | 248 |
245 if (!path->Add(File::PathSeparator())) return false; | 249 if (!path->Add(File::PathSeparator())) return false; |
246 | 250 |
247 // Not a link. Attempt to open as a directory and recurse into the | 251 // Not a link. Attempt to open as a directory and recurse into the |
248 // directory. | 252 // directory. |
249 DIR* dir_pointer; | 253 DIR* dir_pointer; |
250 do { | 254 do { |
251 dir_pointer = opendir(path->data); | 255 dir_pointer = opendir(path->data); |
252 } while (dir_pointer == NULL && errno == EINTR); | 256 } while (dir_pointer == NULL && errno == EINTR); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 int length = strlen(path.data); | 406 int length = strlen(path.data); |
403 result = static_cast<char*>(malloc(length + 1)); | 407 result = static_cast<char*>(malloc(length + 1)); |
404 strncpy(result, path.data, length); | 408 strncpy(result, path.data, length); |
405 result[length] = '\0'; | 409 result[length] = '\0'; |
406 return result; | 410 return result; |
407 } | 411 } |
408 | 412 |
409 | 413 |
410 bool Directory::Delete(const char* dir_name, bool recursive) { | 414 bool Directory::Delete(const char* dir_name, bool recursive) { |
411 if (!recursive) { | 415 if (!recursive) { |
412 return (TEMP_FAILURE_RETRY(remove(dir_name)) == 0); | 416 if (File::GetType(dir_name, false) == File::kIsLink && |
| 417 File::GetType(dir_name, true) == File::kIsDirectory) { |
| 418 return (TEMP_FAILURE_RETRY(unlink(dir_name)) == 0); |
| 419 } |
| 420 return (TEMP_FAILURE_RETRY(rmdir(dir_name)) == 0); |
413 } else { | 421 } else { |
414 PathBuffer path; | 422 PathBuffer path; |
415 if (!path.Add(dir_name)) { | 423 if (!path.Add(dir_name)) { |
416 return false; | 424 return false; |
417 } | 425 } |
418 return DeleteRecursively(&path); | 426 return DeleteRecursively(&path); |
419 } | 427 } |
420 } | 428 } |
421 | 429 |
422 | 430 |
423 bool Directory::Rename(const char* path, const char* new_path) { | 431 bool Directory::Rename(const char* path, const char* new_path) { |
424 ExistsResult exists = Exists(path); | 432 ExistsResult exists = Exists(path); |
425 if (exists != EXISTS) return false; | 433 if (exists != EXISTS) return false; |
426 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); | 434 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); |
427 } | 435 } |
428 | 436 |
429 #endif // defined(TARGET_OS_MACOS) | 437 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |