Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: runtime/bin/directory_posix.cc

Issue 8277033: Add exists, create and delete to directory implementation on Linux and Mac. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix Windows build. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/directory_macos.cc ('k') | runtime/bin/directory_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
« no previous file with comments | « runtime/bin/directory_macos.cc ('k') | runtime/bin/directory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698