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

Unified Diff: runtime/bin/directory_win.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_posix.cc ('k') | tests/standalone/src/DirectoryTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_win.cc
diff --git a/runtime/bin/directory_win.cc b/runtime/bin/directory_win.cc
index 4e5086fec3318f0c4d9735321946909ad677fdd6..d3adfb83e46e3fbc19e026017d6b1a8249f4314c 100644
--- a/runtime/bin/directory_win.cc
+++ b/runtime/bin/directory_win.cc
@@ -2,6 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+#include <errno.h>
+#include <sys/stat.h>
+
#include "bin/directory.h"
// Forward declaration.
@@ -155,6 +158,7 @@ static bool ListRecursively(const char* dir_name,
return completed;
}
+
void Directory::List(const char* dir_name,
bool recursive,
Dart_Port dir_port,
@@ -172,3 +176,40 @@ 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 stat_success = stat(dir_name, &entry_info);
+ if (stat_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) {
+ // 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 == ENAMETOOLONG ||
+ errno == ENOENT ||
+ errno == ENOTDIR);
+ return DOES_NOT_EXIST;
+ }
+}
+
+
+bool Directory::Create(const char* dir_name) {
+ return (CreateDirectory(dir_name, NULL) != 0);
+}
+
+
+bool Directory::Delete(const char* dir_name) {
+ return (RemoveDirectory(dir_name) != 0);
+}
« no previous file with comments | « runtime/bin/directory_posix.cc ('k') | tests/standalone/src/DirectoryTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698