| 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(HOST_OS_LINUX) | 6 #if defined(HOST_OS_LINUX) |
| 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 // implementations (including the glibc implementation), concurrent calls to | 296 // implementations (including the glibc implementation), concurrent calls to |
| 297 // readdir(3) that specify different directory streams are thread-safe." | 297 // readdir(3) that specify different directory streams are thread-safe." |
| 298 dirent* entry = readdir(dir_pointer); | 298 dirent* entry = readdir(dir_pointer); |
| 299 if (entry == NULL) { | 299 if (entry == NULL) { |
| 300 // Failed to read next directory entry. | 300 // Failed to read next directory entry. |
| 301 if (errno != 0) { | 301 if (errno != 0) { |
| 302 break; | 302 break; |
| 303 } | 303 } |
| 304 // End of directory. | 304 // End of directory. |
| 305 int status = NO_RETRY_EXPECTED(closedir(dir_pointer)); | 305 int status = NO_RETRY_EXPECTED(closedir(dir_pointer)); |
| 306 FDUtils::SaveErrorAndClose(fd); | |
| 307 if (status != 0) { | 306 if (status != 0) { |
| 308 return false; | 307 return false; |
| 309 } | 308 } |
| 310 status = | 309 status = |
| 311 NO_RETRY_EXPECTED(unlinkat(dirfd, path->AsString(), AT_REMOVEDIR)); | 310 NO_RETRY_EXPECTED(unlinkat(dirfd, path->AsString(), AT_REMOVEDIR)); |
| 312 return status == 0; | 311 return status == 0; |
| 313 } | 312 } |
| 314 bool ok = false; | 313 bool ok = false; |
| 315 switch (entry->d_type) { | 314 switch (entry->d_type) { |
| 316 case DT_DIR: | 315 case DT_DIR: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 } | 356 } |
| 358 if (!ok) { | 357 if (!ok) { |
| 359 break; | 358 break; |
| 360 } | 359 } |
| 361 path->Reset(path_length); | 360 path->Reset(path_length); |
| 362 } | 361 } |
| 363 // Only happens if an error. | 362 // Only happens if an error. |
| 364 ASSERT(errno != 0); | 363 ASSERT(errno != 0); |
| 365 int err = errno; | 364 int err = errno; |
| 366 VOID_NO_RETRY_EXPECTED(closedir(dir_pointer)); | 365 VOID_NO_RETRY_EXPECTED(closedir(dir_pointer)); |
| 367 FDUtils::SaveErrorAndClose(fd); | |
| 368 errno = err; | 366 errno = err; |
| 369 return false; | 367 return false; |
| 370 } | 368 } |
| 371 | 369 |
| 372 Directory::ExistsResult Directory::Exists(Namespace* namespc, | 370 Directory::ExistsResult Directory::Exists(Namespace* namespc, |
| 373 const char* dir_name) { | 371 const char* dir_name) { |
| 374 NamespaceScope ns(namespc, dir_name); | 372 NamespaceScope ns(namespc, dir_name); |
| 375 struct stat64 entry_info; | 373 struct stat64 entry_info; |
| 376 int success = | 374 int success = |
| 377 TEMP_FAILURE_RETRY(fstatat64(ns.fd(), ns.path(), &entry_info, 0)); | 375 TEMP_FAILURE_RETRY(fstatat64(ns.fd(), ns.path(), &entry_info, 0)); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 NamespaceScope oldns(namespc, old_path); | 500 NamespaceScope oldns(namespc, old_path); |
| 503 NamespaceScope newns(namespc, new_path); | 501 NamespaceScope newns(namespc, new_path); |
| 504 return (NO_RETRY_EXPECTED(renameat(oldns.fd(), oldns.path(), newns.fd(), | 502 return (NO_RETRY_EXPECTED(renameat(oldns.fd(), oldns.path(), newns.fd(), |
| 505 newns.path())) == 0); | 503 newns.path())) == 0); |
| 506 } | 504 } |
| 507 | 505 |
| 508 } // namespace bin | 506 } // namespace bin |
| 509 } // namespace dart | 507 } // namespace dart |
| 510 | 508 |
| 511 #endif // defined(HOST_OS_LINUX) | 509 #endif // defined(HOST_OS_LINUX) |
| OLD | NEW |