| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 return path->Add(dir_name) && DeleteRecursively(path); | 252 return path->Add(dir_name) && DeleteRecursively(path); |
| 253 } | 253 } |
| 254 | 254 |
| 255 | 255 |
| 256 static bool DeleteRecursively(PathBuffer* path) { | 256 static bool DeleteRecursively(PathBuffer* path) { |
| 257 // Do not recurse into links for deletion. Instead delete the link. | 257 // Do not recurse into links for deletion. Instead delete the link. |
| 258 // If it's a file, delete it. | 258 // If it's a file, delete it. |
| 259 struct stat st; | 259 struct stat st; |
| 260 if (NO_RETRY_EXPECTED(lstat(path->AsString(), &st)) == -1) { | 260 if (NO_RETRY_EXPECTED(lstat(path->AsString(), &st)) == -1) { |
| 261 return false; | 261 return false; |
| 262 } else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { | 262 } else if (!S_ISDIR(st.st_mode)) { |
| 263 return (unlink(path->AsString()) == 0); | 263 return (unlink(path->AsString()) == 0); |
| 264 } | 264 } |
| 265 | 265 |
| 266 if (!path->Add(File::PathSeparator())) { | 266 if (!path->Add(File::PathSeparator())) { |
| 267 return false; | 267 return false; |
| 268 } | 268 } |
| 269 | 269 |
| 270 // Not a link. Attempt to open as a directory and recurse into the | 270 // Not a link. Attempt to open as a directory and recurse into the |
| 271 // directory. | 271 // directory. |
| 272 DIR* dir_pointer; | 272 DIR* dir_pointer; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 285 if (result == NULL) { | 285 if (result == NULL) { |
| 286 // End of directory. | 286 // End of directory. |
| 287 return (NO_RETRY_EXPECTED(closedir(dir_pointer)) == 0) && | 287 return (NO_RETRY_EXPECTED(closedir(dir_pointer)) == 0) && |
| 288 (NO_RETRY_EXPECTED(remove(path->AsString())) == 0); | 288 (NO_RETRY_EXPECTED(remove(path->AsString())) == 0); |
| 289 } | 289 } |
| 290 bool ok = false; | 290 bool ok = false; |
| 291 switch (entry.d_type) { | 291 switch (entry.d_type) { |
| 292 case DT_DIR: | 292 case DT_DIR: |
| 293 ok = DeleteDir(entry.d_name, path); | 293 ok = DeleteDir(entry.d_name, path); |
| 294 break; | 294 break; |
| 295 case DT_BLK: |
| 296 case DT_CHR: |
| 297 case DT_FIFO: |
| 298 case DT_SOCK: |
| 295 case DT_REG: | 299 case DT_REG: |
| 296 case DT_LNK: | 300 case DT_LNK: |
| 297 // Treat all links as files. This will delete the link which | 301 // Treat all links as files. This will delete the link which |
| 298 // is what we want no matter if the link target is a file or a | 302 // is what we want no matter if the link target is a file or a |
| 299 // directory. | 303 // directory. |
| 300 ok = DeleteFile(entry.d_name, path); | 304 ok = DeleteFile(entry.d_name, path); |
| 301 break; | 305 break; |
| 302 case DT_UNKNOWN: { | 306 case DT_UNKNOWN: { |
| 303 if (!path->Add(entry.d_name)) { | 307 if (!path->Add(entry.d_name)) { |
| 304 break; | 308 break; |
| 305 } | 309 } |
| 306 // On some file systems the entry type is not determined by | 310 // On some file systems the entry type is not determined by |
| 307 // readdir_r. For those we use lstat to determine the entry | 311 // readdir_r. For those we use lstat to determine the entry |
| 308 // type. | 312 // type. |
| 309 struct stat entry_info; | 313 struct stat entry_info; |
| 310 if (NO_RETRY_EXPECTED(lstat(path->AsString(), &entry_info)) == -1) { | 314 if (NO_RETRY_EXPECTED(lstat(path->AsString(), &entry_info)) == -1) { |
| 311 break; | 315 break; |
| 312 } | 316 } |
| 313 path->Reset(path_length); | 317 path->Reset(path_length); |
| 314 if (S_ISDIR(entry_info.st_mode)) { | 318 if (S_ISDIR(entry_info.st_mode)) { |
| 315 ok = DeleteDir(entry.d_name, path); | 319 ok = DeleteDir(entry.d_name, path); |
| 316 } else if (S_ISREG(entry_info.st_mode) || S_ISLNK(entry_info.st_mode)) { | 320 } else { |
| 317 // Treat links as files. This will delete the link which is | 321 // Treat links as files. This will delete the link which is |
| 318 // what we want no matter if the link target is a file or a | 322 // what we want no matter if the link target is a file or a |
| 319 // directory. | 323 // directory. |
| 320 ok = DeleteFile(entry.d_name, path); | 324 ok = DeleteFile(entry.d_name, path); |
| 321 } | 325 } |
| 322 break; | 326 break; |
| 323 } | 327 } |
| 324 default: | 328 default: |
| 329 // We should have covered all the bases. If not, let's get an error. |
| 330 FATAL1("Unexpected d_type: %d\n", entry.d_type); |
| 325 break; | 331 break; |
| 326 } | 332 } |
| 327 if (!ok) { | 333 if (!ok) { |
| 328 break; | 334 break; |
| 329 } | 335 } |
| 330 path->Reset(path_length); | 336 path->Reset(path_length); |
| 331 } | 337 } |
| 332 // Only happens if an error. | 338 // Only happens if an error. |
| 333 ASSERT(errno != 0); | 339 ASSERT(errno != 0); |
| 334 int err = errno; | 340 int err = errno; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 if (exists != EXISTS) { | 468 if (exists != EXISTS) { |
| 463 return false; | 469 return false; |
| 464 } | 470 } |
| 465 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); | 471 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); |
| 466 } | 472 } |
| 467 | 473 |
| 468 } // namespace bin | 474 } // namespace bin |
| 469 } // namespace dart | 475 } // namespace dart |
| 470 | 476 |
| 471 #endif // defined(TARGET_OS_MACOS) | 477 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |