| 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 "bin/directory.h" | 5 #include "bin/directory.h" |
| 6 | 6 |
| 7 #include <dirent.h> | 7 #include <dirent.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <sys/param.h> | 9 #include <sys/param.h> |
| 10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 // Iterated the directory and post the directories and files to the | 128 // Iterated the directory and post the directories and files to the |
| 129 // ports. | 129 // ports. |
| 130 int read = 0; | 130 int read = 0; |
| 131 bool success = true; | 131 bool success = true; |
| 132 dirent entry; | 132 dirent entry; |
| 133 dirent* result; | 133 dirent* result; |
| 134 while ((read = TEMP_FAILURE_RETRY(readdir_r(dir_pointer, | 134 while ((read = TEMP_FAILURE_RETRY(readdir_r(dir_pointer, |
| 135 &entry, | 135 &entry, |
| 136 &result))) == 0 && | 136 &result))) == 0 && |
| 137 result != NULL && | 137 result != NULL) { |
| 138 success) { | |
| 139 switch (entry.d_type) { | 138 switch (entry.d_type) { |
| 140 case DT_DIR: | 139 case DT_DIR: |
| 141 success = success && HandleDir(entry.d_name, | 140 success = HandleDir(entry.d_name, |
| 142 path, | 141 path, |
| 143 path_length, | 142 path_length, |
| 144 recursive, | 143 recursive, |
| 145 listing); | 144 listing) && success; |
| 146 break; | 145 break; |
| 147 case DT_REG: | 146 case DT_REG: |
| 148 success = success && HandleFile(entry.d_name, | 147 success = HandleFile(entry.d_name, |
| 149 path, | 148 path, |
| 150 path_length, | 149 path_length, |
| 151 listing); | 150 listing) && success; |
| 152 break; | 151 break; |
| 153 case DT_LNK: | 152 case DT_LNK: |
| 154 case DT_UNKNOWN: { | 153 case DT_UNKNOWN: { |
| 155 // On some file systems the entry type is not determined by | 154 // On some file systems the entry type is not determined by |
| 156 // readdir_r. For those and for links we use stat to determine | 155 // readdir_r. For those and for links we use stat to determine |
| 157 // the actual entry type. Notice that stat returns the type of | 156 // the actual entry type. Notice that stat returns the type of |
| 158 // the file pointed to. | 157 // the file pointed to. |
| 159 struct stat entry_info; | 158 struct stat entry_info; |
| 160 size_t written = snprintf(path + path_length, | 159 size_t written = snprintf(path + path_length, |
| 161 PATH_MAX - path_length, | 160 PATH_MAX - path_length, |
| 162 "%s", | 161 "%s", |
| 163 entry.d_name); | 162 entry.d_name); |
| 164 if (written != strlen(entry.d_name)) { | 163 if (written != strlen(entry.d_name)) { |
| 165 success = false; | 164 success = false; |
| 166 break; | 165 break; |
| 167 } | 166 } |
| 168 int stat_success = TEMP_FAILURE_RETRY(stat(path, &entry_info)); | 167 int stat_success = TEMP_FAILURE_RETRY(stat(path, &entry_info)); |
| 169 if (stat_success == -1) { | 168 if (stat_success == -1) { |
| 170 success = false; | 169 success = false; |
| 171 PostError(listing, path); | 170 PostError(listing, path); |
| 172 break; | 171 break; |
| 173 } | 172 } |
| 174 if (S_ISDIR(entry_info.st_mode)) { | 173 if (S_ISDIR(entry_info.st_mode)) { |
| 175 success = success && HandleDir(entry.d_name, | 174 success = HandleDir(entry.d_name, |
| 176 path, | 175 path, |
| 177 path_length, | 176 path_length, |
| 178 recursive, | 177 recursive, |
| 179 listing); | 178 listing) && success; |
| 180 } else if (S_ISREG(entry_info.st_mode)) { | 179 } else if (S_ISREG(entry_info.st_mode)) { |
| 181 success = success && HandleFile(entry.d_name, | 180 success = HandleFile(entry.d_name, |
| 182 path, | 181 path, |
| 183 path_length, | 182 path_length, |
| 184 listing); | 183 listing) && success; |
| 185 } | 184 } |
| 186 ASSERT(!S_ISLNK(entry_info.st_mode)); | 185 ASSERT(!S_ISLNK(entry_info.st_mode)); |
| 187 break; | 186 break; |
| 188 } | 187 } |
| 189 default: | 188 default: |
| 190 break; | 189 break; |
| 191 } | 190 } |
| 192 } | 191 } |
| 193 | 192 |
| 194 if (read != 0) { | 193 if (read != 0) { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 } | 416 } |
| 418 | 417 |
| 419 | 418 |
| 420 bool Directory::Delete(const char* dir_name, bool recursive) { | 419 bool Directory::Delete(const char* dir_name, bool recursive) { |
| 421 if (!recursive) { | 420 if (!recursive) { |
| 422 return (TEMP_FAILURE_RETRY(remove(dir_name)) == 0); | 421 return (TEMP_FAILURE_RETRY(remove(dir_name)) == 0); |
| 423 } else { | 422 } else { |
| 424 return DeleteRecursively(dir_name); | 423 return DeleteRecursively(dir_name); |
| 425 } | 424 } |
| 426 } | 425 } |
| OLD | NEW |