Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: runtime/bin/directory_fuchsia.cc

Issue 3005883002: [dart:io] Remove double-close from recursive directory delete (Closed)
Patch Set: Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/directory_android.cc ('k') | runtime/bin/directory_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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(HOST_OS_FUCHSIA) 6 #if defined(HOST_OS_FUCHSIA)
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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 // implementations (including the glibc implementation), concurrent calls to 406 // implementations (including the glibc implementation), concurrent calls to
407 // readdir(3) that specify different directory streams are thread-safe." 407 // readdir(3) that specify different directory streams are thread-safe."
408 dirent* entry = readdir(dir_pointer); 408 dirent* entry = readdir(dir_pointer);
409 if (entry == NULL) { 409 if (entry == NULL) {
410 // Failed to read next directory entry. 410 // Failed to read next directory entry.
411 if (errno != 0) { 411 if (errno != 0) {
412 break; 412 break;
413 } 413 }
414 // End of directory. 414 // End of directory.
415 int status = NO_RETRY_EXPECTED(closedir(dir_pointer)); 415 int status = NO_RETRY_EXPECTED(closedir(dir_pointer));
416 FDUtils::SaveErrorAndClose(fd);
417 if (status != 0) { 416 if (status != 0) {
418 return false; 417 return false;
419 } 418 }
420 status = 419 status =
421 NO_RETRY_EXPECTED(unlinkat(dirfd, path->AsString(), AT_REMOVEDIR)); 420 NO_RETRY_EXPECTED(unlinkat(dirfd, path->AsString(), AT_REMOVEDIR));
422 return status == 0; 421 return status == 0;
423 } 422 }
424 bool ok = false; 423 bool ok = false;
425 switch (entry->d_type) { 424 switch (entry->d_type) {
426 case DT_DIR: 425 case DT_DIR:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 466 }
468 if (!ok) { 467 if (!ok) {
469 break; 468 break;
470 } 469 }
471 path->Reset(path_length); 470 path->Reset(path_length);
472 } 471 }
473 // Only happens if an error. 472 // Only happens if an error.
474 ASSERT(errno != 0); 473 ASSERT(errno != 0);
475 int err = errno; 474 int err = errno;
476 VOID_NO_RETRY_EXPECTED(closedir(dir_pointer)); 475 VOID_NO_RETRY_EXPECTED(closedir(dir_pointer));
477 FDUtils::SaveErrorAndClose(fd);
478 errno = err; 476 errno = err;
479 return false; 477 return false;
480 } 478 }
481 479
482 bool Directory::Delete(Namespace* namespc, 480 bool Directory::Delete(Namespace* namespc,
483 const char* dir_name, 481 const char* dir_name,
484 bool recursive) { 482 bool recursive) {
485 NamespaceScope ns(namespc, dir_name); 483 NamespaceScope ns(namespc, dir_name);
486 if (!recursive) { 484 if (!recursive) {
487 if ((File::GetType(namespc, dir_name, false) == File::kIsLink) && 485 if ((File::GetType(namespc, dir_name, false) == File::kIsLink) &&
(...skipping 20 matching lines...) Expand all
508 NamespaceScope oldns(namespc, old_path); 506 NamespaceScope oldns(namespc, old_path);
509 NamespaceScope newns(namespc, new_path); 507 NamespaceScope newns(namespc, new_path);
510 return (NO_RETRY_EXPECTED(renameat(oldns.fd(), oldns.path(), newns.fd(), 508 return (NO_RETRY_EXPECTED(renameat(oldns.fd(), oldns.path(), newns.fd(),
511 newns.path())) == 0); 509 newns.path())) == 0);
512 } 510 }
513 511
514 } // namespace bin 512 } // namespace bin
515 } // namespace dart 513 } // namespace dart
516 514
517 #endif // defined(HOST_OS_FUCHSIA) 515 #endif // defined(HOST_OS_FUCHSIA)
OLDNEW
« no previous file with comments | « runtime/bin/directory_android.cc ('k') | runtime/bin/directory_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698