| 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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 int length = strnlen(path.data, PATH_MAX); | 438 int length = strnlen(path.data, PATH_MAX); |
| 435 result = static_cast<char*>(malloc(length + 1)); | 439 result = static_cast<char*>(malloc(length + 1)); |
| 436 strncpy(result, path.data, length); | 440 strncpy(result, path.data, length); |
| 437 result[length] = '\0'; | 441 result[length] = '\0'; |
| 438 return result; | 442 return result; |
| 439 } | 443 } |
| 440 | 444 |
| 441 | 445 |
| 442 bool Directory::Delete(const char* dir_name, bool recursive) { | 446 bool Directory::Delete(const char* dir_name, bool recursive) { |
| 443 if (!recursive) { | 447 if (!recursive) { |
| 444 return (TEMP_FAILURE_RETRY(remove(dir_name)) == 0); | 448 if (File::GetType(dir_name, false) == File::kIsLink && |
| 449 File::GetType(dir_name, true) == File::kIsDirectory) { |
| 450 return (TEMP_FAILURE_RETRY(unlink(dir_name)) == 0); |
| 451 } |
| 452 return (TEMP_FAILURE_RETRY(rmdir(dir_name)) == 0); |
| 445 } else { | 453 } else { |
| 446 PathBuffer path; | 454 PathBuffer path; |
| 447 if (!path.Add(dir_name)) { | 455 if (!path.Add(dir_name)) { |
| 448 return false; | 456 return false; |
| 449 } | 457 } |
| 450 return DeleteRecursively(&path); | 458 return DeleteRecursively(&path); |
| 451 } | 459 } |
| 452 } | 460 } |
| 453 | 461 |
| 454 | 462 |
| 455 bool Directory::Rename(const char* path, const char* new_path) { | 463 bool Directory::Rename(const char* path, const char* new_path) { |
| 456 ExistsResult exists = Exists(path); | 464 ExistsResult exists = Exists(path); |
| 457 if (exists != EXISTS) return false; | 465 if (exists != EXISTS) return false; |
| 458 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); | 466 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); |
| 459 } | 467 } |
| 460 | 468 |
| 461 #endif // defined(TARGET_OS_ANDROID) | 469 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |