OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 <dirent.h> | 5 #include <dirent.h> |
| 6 #include <errno.h> |
6 #include <libgen.h> | 7 #include <libgen.h> |
7 #include <string.h> | 8 #include <string.h> |
8 #include <sys/param.h> | 9 #include <sys/param.h> |
9 #include <sys/stat.h> | 10 #include <sys/stat.h> |
10 #include <sys/types.h> | 11 #include <sys/types.h> |
11 #include <unistd.h> | 12 #include <unistd.h> |
12 | 13 |
13 #include "bin/dartutils.h" | 14 #include "bin/dartutils.h" |
14 #include "bin/directory.h" | 15 #include "bin/directory.h" |
15 #include "bin/file.h" | 16 #include "bin/file.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 recursive, | 211 recursive, |
211 dir_port, | 212 dir_port, |
212 file_port, | 213 file_port, |
213 done_port, | 214 done_port, |
214 error_port); | 215 error_port); |
215 if (done_port != 0) { | 216 if (done_port != 0) { |
216 Dart_Handle value = Dart_NewBoolean(completed); | 217 Dart_Handle value = Dart_NewBoolean(completed); |
217 Dart_Post(done_port, value); | 218 Dart_Post(done_port, value); |
218 } | 219 } |
219 } | 220 } |
| 221 |
| 222 |
| 223 bool Directory::Exists(const char* dir_name, bool* result) { |
| 224 struct stat entry_info; |
| 225 int lstat_success = lstat(dir_name, &entry_info); |
| 226 if (lstat_success == 0) { |
| 227 *result = ((entry_info.st_mode & S_IFMT) == S_IFDIR); |
| 228 return true; |
| 229 } else { |
| 230 if (errno == EACCES || |
| 231 errno == EBADF || |
| 232 errno == EFAULT || |
| 233 errno == ENOMEM || |
| 234 errno == EOVERFLOW) { |
| 235 // Search permissions denied for one of the directories in the |
| 236 // path or a low level error occured. We do not know if the |
| 237 // directory exists. |
| 238 return false; |
| 239 } |
| 240 ASSERT(errno == ELOOP || |
| 241 errno == ENAMETOOLONG || |
| 242 errno == ENOENT || |
| 243 errno == ENOTDIR); |
| 244 *result = false; |
| 245 return true; |
| 246 } |
| 247 } |
| 248 |
| 249 |
| 250 bool Directory::Create(const char* dir_name) { |
| 251 // Create the directory with the permissions specified by the |
| 252 // process umask. |
| 253 return (mkdir(dir_name, 0777) == 0); |
| 254 } |
| 255 |
| 256 |
| 257 bool Directory::Delete(const char* dir_name) { |
| 258 return (rmdir(dir_name) == 0); |
| 259 } |
OLD | NEW |