Index: runtime/bin/directory_posix.cc |
diff --git a/runtime/bin/directory_linux.cc b/runtime/bin/directory_posix.cc |
similarity index 87% |
rename from runtime/bin/directory_linux.cc |
rename to runtime/bin/directory_posix.cc |
index 641c0cf6d433891b059f3e830ce76b142c5e10c0..f24371a4d3989449875340351eca1a18d6d3470e 100644 |
--- a/runtime/bin/directory_linux.cc |
+++ b/runtime/bin/directory_posix.cc |
@@ -3,6 +3,7 @@ |
// BSD-style license that can be found in the LICENSE file. |
#include <dirent.h> |
+#include <errno.h> |
#include <libgen.h> |
#include <string.h> |
#include <sys/param.h> |
@@ -217,3 +218,44 @@ void Directory::List(const char* dir_name, |
Dart_Post(done_port, value); |
} |
} |
+ |
+ |
+Directory::ExistsResult Directory::Exists(const char* dir_name) { |
+ struct stat entry_info; |
+ int lstat_success = lstat(dir_name, &entry_info); |
+ if (lstat_success == 0) { |
+ if ((entry_info.st_mode & S_IFMT) == S_IFDIR) { |
+ return EXISTS; |
+ } else { |
+ return DOES_NOT_EXIST; |
+ } |
+ } else { |
+ if (errno == EACCES || |
+ errno == EBADF || |
+ errno == EFAULT || |
+ errno == ENOMEM || |
+ errno == EOVERFLOW) { |
+ // Search permissions denied for one of the directories in the |
+ // path or a low level error occured. We do not know if the |
+ // directory exists. |
+ return UNKNOWN; |
+ } |
+ ASSERT(errno == ELOOP || |
+ errno == ENAMETOOLONG || |
+ errno == ENOENT || |
+ errno == ENOTDIR); |
+ return DOES_NOT_EXIST; |
+ } |
+} |
+ |
+ |
+bool Directory::Create(const char* dir_name) { |
+ // Create the directory with the permissions specified by the |
+ // process umask. |
+ return (mkdir(dir_name, 0777) == 0); |
+} |
+ |
+ |
+bool Directory::Delete(const char* dir_name) { |
+ return (rmdir(dir_name) == 0); |
+} |