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 "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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 if (S_ISREG(entry_info.st_mode) || S_ISCHR(entry_info.st_mode) || |
|
rmacnak
2016/12/14 18:44:02
Keep S_ISLNK
zra
2016/12/14 20:48:07
Done.
| |
| 321 S_ISBLK(entry_info.st_mode) || | |
| 322 S_ISFIFO(entry_info.st_mode) || | |
| 323 S_ISSOCK(entry_info.st_mode)) { | |
| 317 // Treat links as files. This will delete the link which is | 324 // 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 | 325 // what we want no matter if the link target is a file or a |
| 319 // directory. | 326 // directory. |
| 320 ok = DeleteFile(entry.d_name, path); | 327 ok = DeleteFile(entry.d_name, path); |
| 328 } else { | |
| 329 FATAL1("Unexpected st_mode: %d\n", entry_info.st_mode); | |
| 321 } | 330 } |
| 322 break; | 331 break; |
| 323 } | 332 } |
| 324 default: | 333 default: |
| 334 // We should have covered all the bases. If not, let's get an error. | |
| 335 FATAL1("Unexpected d_type: %d\n", entry.d_type); | |
| 325 break; | 336 break; |
| 326 } | 337 } |
| 327 if (!ok) { | 338 if (!ok) { |
| 328 break; | 339 break; |
| 329 } | 340 } |
| 330 path->Reset(path_length); | 341 path->Reset(path_length); |
| 331 } | 342 } |
| 332 // Only happens if an error. | 343 // Only happens if an error. |
| 333 ASSERT(errno != 0); | 344 ASSERT(errno != 0); |
| 334 int err = errno; | 345 int err = errno; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 if (exists != EXISTS) { | 478 if (exists != EXISTS) { |
| 468 return false; | 479 return false; |
| 469 } | 480 } |
| 470 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); | 481 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); |
| 471 } | 482 } |
| 472 | 483 |
| 473 } // namespace bin | 484 } // namespace bin |
| 474 } // namespace dart | 485 } // namespace dart |
| 475 | 486 |
| 476 #endif // defined(TARGET_OS_ANDROID) | 487 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |