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

Unified Diff: runtime/bin/file_impl.dart

Issue 9416096: Implement File.directory() and File.directorySync() to get (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Implement async version using isolate Created 8 years, 10 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
Index: runtime/bin/file_impl.dart
diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
index 9efffbef622c31c7858117ade266a9a487471d4a..a4966bd7954dd936a4d720d6b29be38f4b22990c 100644
--- a/runtime/bin/file_impl.dart
+++ b/runtime/bin/file_impl.dart
@@ -404,6 +404,24 @@ class _DeleteOperation extends _FileOperation {
}
+class _DirectoryOperation extends _FileOperation {
+ _DirectoryOperation(String this._name);
+
+ void execute(ReceivePort port) {
+ if (_name is String) {
+ if (_FileUtils.exists(_name)) {
+ _replyPort.send(_FileUtils.directory(_name), port.toSendPort());
+ return;
+ }
+ }
+ // Either _name is not a string or the file does not exist.
+ _replyPort.send(null, port.toSendPort());
+ }
+
+ String _name;
+}
+
+
class _ExitOperation extends _FileOperation {
void execute(ReceivePort port) {
port.close();
@@ -479,6 +497,7 @@ class _FileUtils {
static int open(String name, int mode) native "File_Open";
static bool create(String name) native "File_Create";
static bool delete(String name) native "File_Delete";
+ static bool directory(String name) native "File_Directory";
static String fullPath(String name) native "File_FullPath";
static int close(int id) native "File_Close";
static int readByte(int id) native "File_ReadByte";
@@ -637,6 +656,32 @@ class _File implements File {
}
}
+ void directory() {
+ _asyncUsed = true;
+ var handleDirectoryResult = (path, ignored) {
+ var handler =
+ (_directoryHandler != null) ? _directoryHandler : (s) => null;
+ if (path != null) {
+ handler(new Directory(path));
+ } else if (_errorHandler != null) {
+ _errorHandler("Cannot get containing directory for: ${_name}");
+ }
+ };
+ var operation = new _DirectoryOperation(_name);
+ _scheduler.enqueue(operation, handleDirectoryResult);
+ }
+
+ void directorySync() {
+ if (_asyncUsed) {
+ throw new FileIOException(
+ "Mixed use of synchronous and asynchronous API");
+ }
+ if (!existsSync()) {
+ throw new FileIOException("Cannot get directory for: $_name");
+ }
+ return new Directory(_FileUtils.directory(_name));
+ }
+
void open([FileMode mode = FileMode.READ]) {
_asyncUsed = true;
if (mode != FileMode.READ &&
@@ -796,6 +841,10 @@ class _File implements File {
_deleteHandler = handler;
}
+ void set directoryHandler(void handler(String path)) {
+ _directoryHandler = handler;
+ }
+
void set openHandler(void handler(RandomAccessFile file)) {
_openHandler = handler;
}
@@ -824,6 +873,7 @@ class _File implements File {
Function _existsHandler;
Function _createHandler;
Function _deleteHandler;
+ Function _directoryHandler;
Function _openHandler;
Function _inputStreamHandler;
Function _outputStreamHandler;
« no previous file with comments | « runtime/bin/file.dart ('k') | runtime/bin/file_linux.cc » ('j') | runtime/bin/file_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698