Index: sdk/lib/io/directory_impl.dart |
diff --git a/sdk/lib/io/directory_impl.dart b/sdk/lib/io/directory_impl.dart |
index 9b43b8e962333d61d0cce020810bc611267fe0cf..1aa3202edc6d3b2a15475a61661e912fcf2133f0 100644 |
--- a/sdk/lib/io/directory_impl.dart |
+++ b/sdk/lib/io/directory_impl.dart |
@@ -14,19 +14,21 @@ class _Directory extends FileSystemEntity implements Directory { |
} |
} |
- external static _current(); |
- external static _setCurrent(path); |
- external static _createTemp(String path); |
- external static String _systemTemp(); |
- external static _exists(String path); |
- external static _create(String path); |
- external static _deleteNative(String path, bool recursive); |
- external static _rename(String path, String newPath); |
- external static void _fillWithDirectoryListing(List<FileSystemEntity> list, |
+ external static _current(_Namespace namespace); |
+ external static _setCurrent(_Namespace namespace, path); |
+ external static _createTemp(_Namespace namespace, String path); |
+ external static String _systemTemp(_Namespace namespace); |
+ external static _exists(_Namespace namespace, String path); |
+ external static _create(_Namespace namespace, String path); |
+ external static _deleteNative( |
+ _Namespace namespace, String path, bool recursive); |
+ external static _rename(_Namespace namespace, String path, String newPath); |
+ external static void _fillWithDirectoryListing( |
+ _Namespace namespace, List<FileSystemEntity> list, |
String path, bool recursive, bool followLinks); |
static Directory get current { |
- var result = _current(); |
+ var result = _current(_Namespace._namespace); |
if (result is OSError) { |
throw new FileSystemException( |
"Getting current working directory failed", "", result); |
@@ -34,9 +36,11 @@ class _Directory extends FileSystemEntity implements Directory { |
return new _Directory(result); |
} |
+ // TODO(zra): Provide a flag that an embedder can set to make attempts to set |
+ // the working directory for the whole process fail. |
static void set current(path) { |
if (path is Directory) path = path.path; |
- var result = _setCurrent(path); |
+ var result = _setCurrent(_Namespace._namespace, path); |
if (result is ArgumentError) throw result; |
if (result is OSError) { |
throw new FileSystemException( |
@@ -49,7 +53,8 @@ class _Directory extends FileSystemEntity implements Directory { |
} |
Future<bool> exists() { |
- return _IOService._dispatch(_DIRECTORY_EXISTS, [path]).then((response) { |
+ return _File._dispatchWithNamespace(_DIRECTORY_EXISTS, [null, path]) |
+ .then((response) { |
if (_isErrorResponse(response)) { |
throw _exceptionOrErrorFromResponse(response, "Exists failed"); |
} |
@@ -58,7 +63,7 @@ class _Directory extends FileSystemEntity implements Directory { |
} |
bool existsSync() { |
- var result = _exists(path); |
+ var result = _exists(_Namespace._namespace, path); |
if (result is OSError) { |
throw new FileSystemException("Exists failed", path, result); |
} |
@@ -80,7 +85,8 @@ class _Directory extends FileSystemEntity implements Directory { |
} |
}); |
} else { |
- return _IOService._dispatch(_DIRECTORY_CREATE, [path]).then((response) { |
+ return _File._dispatchWithNamespace(_DIRECTORY_CREATE, [null, path]) |
+ .then((response) { |
if (_isErrorResponse(response)) { |
throw _exceptionOrErrorFromResponse(response, "Creation failed"); |
} |
@@ -96,13 +102,14 @@ class _Directory extends FileSystemEntity implements Directory { |
parent.createSync(recursive: true); |
} |
} |
- var result = _create(path); |
+ var result = _create(_Namespace._namespace, path); |
if (result is OSError) { |
throw new FileSystemException("Creation failed", path, result); |
} |
} |
- static Directory get systemTemp => new Directory(_systemTemp()); |
+ static Directory get systemTemp => |
+ new Directory(_systemTemp(_Namespace._namespace)); |
Future<Directory> createTemp([String prefix]) { |
if (prefix == null) prefix = ''; |
@@ -116,8 +123,9 @@ class _Directory extends FileSystemEntity implements Directory { |
} else { |
fullPrefix = "$path${Platform.pathSeparator}$prefix"; |
} |
- return _IOService |
- ._dispatch(_DIRECTORY_CREATE_TEMP, [fullPrefix]).then((response) { |
+ return _File |
+ ._dispatchWithNamespace(_DIRECTORY_CREATE_TEMP, [null, fullPrefix]) |
+ .then((response) { |
if (_isErrorResponse(response)) { |
throw _exceptionOrErrorFromResponse( |
response, "Creation of temporary directory failed"); |
@@ -138,7 +146,7 @@ class _Directory extends FileSystemEntity implements Directory { |
} else { |
fullPrefix = "$path${Platform.pathSeparator}$prefix"; |
} |
- var result = _createTemp(fullPrefix); |
+ var result = _createTemp(_Namespace._namespace, fullPrefix); |
if (result is OSError) { |
throw new FileSystemException( |
"Creation of temporary directory failed", fullPrefix, result); |
@@ -147,8 +155,9 @@ class _Directory extends FileSystemEntity implements Directory { |
} |
Future<Directory> _delete({bool recursive: false}) { |
- return _IOService |
- ._dispatch(_DIRECTORY_DELETE, [path, recursive]).then((response) { |
+ return _File |
+ ._dispatchWithNamespace(_DIRECTORY_DELETE, [null, path, recursive]) |
+ .then((response) { |
if (_isErrorResponse(response)) { |
throw _exceptionOrErrorFromResponse(response, "Deletion failed"); |
} |
@@ -157,15 +166,16 @@ class _Directory extends FileSystemEntity implements Directory { |
} |
void _deleteSync({bool recursive: false}) { |
- var result = _deleteNative(path, recursive); |
+ var result = _deleteNative(_Namespace._namespace, path, recursive); |
if (result is OSError) { |
throw new FileSystemException("Deletion failed", path, result); |
} |
} |
Future<Directory> rename(String newPath) { |
- return _IOService |
- ._dispatch(_DIRECTORY_RENAME, [path, newPath]).then((response) { |
+ return _File |
+ ._dispatchWithNamespace(_DIRECTORY_RENAME, [null, path, newPath]) |
+ .then((response) { |
if (_isErrorResponse(response)) { |
throw _exceptionOrErrorFromResponse(response, "Rename failed"); |
} |
@@ -177,7 +187,7 @@ class _Directory extends FileSystemEntity implements Directory { |
if (newPath is! String) { |
throw new ArgumentError(); |
} |
- var result = _rename(path, newPath); |
+ var result = _rename(_Namespace._namespace, path, newPath); |
if (result is OSError) { |
throw new FileSystemException("Rename failed", path, result); |
} |
@@ -200,6 +210,7 @@ class _Directory extends FileSystemEntity implements Directory { |
} |
var result = <FileSystemEntity>[]; |
_fillWithDirectoryListing( |
+ _Namespace._namespace, |
result, |
FileSystemEntity._ensureTrailingPathSeparators(path), |
recursive, |
@@ -261,6 +272,7 @@ class _AsyncDirectoryLister { |
onListen: onListen, onResume: onResume, onCancel: onCancel, sync: true); |
} |
+ // WARNING: |
// Calling this function will increase the reference count on the native |
// object that implements the async directory lister operations. It should |
// only be called to pass the pointer to the IO Service, which will decrement |
@@ -272,8 +284,9 @@ class _AsyncDirectoryLister { |
Stream<FileSystemEntity> get stream => controller.stream; |
void onListen() { |
- _IOService._dispatch( |
- _DIRECTORY_LIST_START, [path, recursive, followLinks]).then((response) { |
+ _File._dispatchWithNamespace( |
+ _DIRECTORY_LIST_START, [null, path, recursive, followLinks]) |
+ .then((response) { |
if (response is int) { |
_ops = new _AsyncDirectoryListerOps(response); |
next(); |