| 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_LINUX) | 6 #if defined(TARGET_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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Reset. | 98 // Reset. |
| 99 listing->path_buffer().Reset(path_length_); | 99 listing->path_buffer().Reset(path_length_); |
| 100 ResetLink(); | 100 ResetLink(); |
| 101 | 101 |
| 102 // Iterate the directory and post the directories and files to the | 102 // Iterate the directory and post the directories and files to the |
| 103 // ports. | 103 // ports. |
| 104 int status = 0; | 104 int status = 0; |
| 105 dirent entry; | 105 dirent entry; |
| 106 dirent* result; | 106 dirent* result; |
| 107 if ((status = TEMP_FAILURE_RETRY(readdir_r(reinterpret_cast<DIR*>(lister_), | 107 if ((status = TEMP_FAILURE_RETRY(readdir_r(reinterpret_cast<DIR*>(lister_), |
| 108 &entry, | 108 &entry, |
| 109 &result))) == 0 && | 109 &result))) == 0 && |
| 110 result != NULL) { | 110 result != NULL) { |
| 111 if (!listing->path_buffer().Add(entry.d_name)) { | 111 if (!listing->path_buffer().Add(entry.d_name)) { |
| 112 done_ = true; | 112 done_ = true; |
| 113 return kListError; | 113 return kListError; |
| 114 } | 114 } |
| 115 switch (entry.d_type) { | 115 switch (entry.d_type) { |
| 116 case DT_DIR: | 116 case DT_DIR: |
| 117 if (strcmp(entry.d_name, ".") == 0) return Next(listing); | 117 if (strcmp(entry.d_name, ".") == 0) return Next(listing); |
| 118 if (strcmp(entry.d_name, "..") == 0) return Next(listing); | 118 if (strcmp(entry.d_name, "..") == 0) return Next(listing); |
| 119 return kListDirectory; | 119 return kListDirectory; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 break; | 181 break; |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 done_ = true; | 184 done_ = true; |
| 185 | 185 |
| 186 if (status != 0) { | 186 if (status != 0) { |
| 187 errno = status; | 187 errno = status; |
| 188 return kListError; | 188 return kListError; |
| 189 } | 189 } |
| 190 | 190 |
| 191 if (closedir(reinterpret_cast<DIR*>(lister_)) == -1) { | |
| 192 return kListError; | |
| 193 } | |
| 194 | |
| 195 return kListDone; | 191 return kListDone; |
| 196 } | 192 } |
| 197 | 193 |
| 198 | 194 |
| 195 DirectoryListingEntry::~DirectoryListingEntry() { |
| 196 ResetLink(); |
| 197 if (lister_ != 0) { |
| 198 closedir(reinterpret_cast<DIR*>(lister_)); |
| 199 } |
| 200 } |
| 201 |
| 202 |
| 199 void DirectoryListingEntry::ResetLink() { | 203 void DirectoryListingEntry::ResetLink() { |
| 200 if (link_ != NULL && (parent_ == NULL || parent_->link_ != link_)) { | 204 if (link_ != NULL && (parent_ == NULL || parent_->link_ != link_)) { |
| 201 delete link_; | 205 delete link_; |
| 202 link_ = NULL; | 206 link_ = NULL; |
| 203 } | 207 } |
| 204 if (parent_ != NULL) { | 208 if (parent_ != NULL) { |
| 205 link_ = parent_->link_; | 209 link_ = parent_->link_; |
| 206 } | 210 } |
| 207 } | 211 } |
| 208 | 212 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 bool Directory::Rename(const char* path, const char* new_path) { | 437 bool Directory::Rename(const char* path, const char* new_path) { |
| 434 ExistsResult exists = Exists(path); | 438 ExistsResult exists = Exists(path); |
| 435 if (exists != EXISTS) return false; | 439 if (exists != EXISTS) return false; |
| 436 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); | 440 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); |
| 437 } | 441 } |
| 438 | 442 |
| 439 } // namespace bin | 443 } // namespace bin |
| 440 } // namespace dart | 444 } // namespace dart |
| 441 | 445 |
| 442 #endif // defined(TARGET_OS_LINUX) | 446 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |