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..96aa022378dc54018f5a33353cdfaf895af03f63 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,42 @@ void Directory::List(const char* dir_name, |
Dart_Post(done_port, value); |
} |
} |
+ |
+ |
+bool Directory::Exists(const char* dir_name, bool* result) { |
+ struct stat entry_info; |
+ int lstat_success = lstat(dir_name, &entry_info); |
+ if (lstat_success == 0) { |
+ *result = ((entry_info.st_mode & S_IFMT) == S_IFDIR); |
+ return true; |
+ } 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 false; |
+ } |
+ ASSERT(errno == ELOOP || |
+ errno == ENAMETOOLONG || |
+ errno == ENOENT || |
+ errno == ENOTDIR); |
+ *result = false; |
+ return true; |
+ } |
+} |
+ |
+ |
+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); |
+} |