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

Unified Diff: sdk/lib/io/file_system_entity.dart

Issue 14907002: dart:io | Implement asynchronous versions of FileSystemEntity methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add implementation of FileSystemEntity.type, and refactor error handling. Created 7 years, 8 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 | « sdk/lib/io/file_impl.dart ('k') | tests/standalone/io/file_invalid_arguments_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/file_system_entity.dart
diff --git a/sdk/lib/io/file_system_entity.dart b/sdk/lib/io/file_system_entity.dart
index 0649d18e474470e4cdbb7516754f815280067c66..907d25a3823548ce0f0649cc37f26fa8037af0c0 100644
--- a/sdk/lib/io/file_system_entity.dart
+++ b/sdk/lib/io/file_system_entity.dart
@@ -34,8 +34,8 @@ class FileSystemEntityType {
abstract class FileSystemEntity {
String get path;
- external static int _getType(String path, bool followLinks);
- external static bool _identical(String path1, String path2);
+ external static _getType(String path, bool followLinks);
+ external static _identical(String path1, String path2);
static int _getTypeSync(String path, bool followLinks) {
var result = _getType(path, followLinks);
@@ -43,8 +43,21 @@ abstract class FileSystemEntity {
return result;
}
- static Future<int> _getTypeAsync(String path, bool followLinks) =>
- new Future(() => _getTypeSync(path, followLinks));
+ static Future<int> _getTypeAsync(String path, bool followLinks) {
+ // Get a new file service port for each request. We could also cache one.
+ var service = _FileUtils._newServicePort();
+ List request = new List(3);
+ request[0] = _TYPE_REQUEST;
+ request[1] = path;
+ request[2] = followLinks;
+ return service.call(request).then((response) {
+ if (_isErrorResponse(response)) {
+ throw _exceptionFromResponse(response,
+ "Error getting type of '$_path'");
+ }
+ return response;
+ });
+ }
/**
* Do two paths refer to the same object in the file system?
@@ -56,8 +69,22 @@ abstract class FileSystemEntity {
* exist.
* The target of a link can be compared by first getting it with Link.target.
*/
- static Future<bool> identical(String path1, String path2) =>
- new Future<bool>(() => identicalSync(path1, path2));
+ static Future<bool> identical(String path1, String path2) {
+ // Get a new file service port for each request. We could also cache one.
+ var service = _FileUtils._newServicePort();
+ List request = new List(3);
+ request[0] = _IDENTICAL_REQUEST;
+ request[1] = path1;
+ request[2] = path2;
+ return service.call(request).then((response) {
+ if (_isErrorResponse(response)) {
+ throw _exceptionFromResponse(response,
+ "Error in FileSystemEntity.identical($path1, $path2)");
+ }
+ return response;
+ });
+ }
+
/**
* Do two paths refer to the same object in the file system?
@@ -71,14 +98,13 @@ abstract class FileSystemEntity {
*/
static bool identicalSync(String path1, String path2) {
var result = _identical(path1, path2);
- _throwIfError(result, 'Error in FileSystemEntity.identical');
+ _throwIfError(result, 'Error in FileSystemEntity.identicalSync');
return result;
}
static Future<FileSystemEntityType> type(String path,
{bool followLinks: true})
- => new Future<FileSystemEntityType>(
- () => typeSync(path, followLinks: followLinks));
+ => _getTypeAsync(path, followLinks).then(FileSystemEntityType._lookup);
static FileSystemEntityType typeSync(String path, {bool followLinks: true})
=> FileSystemEntityType._lookup(_getTypeSync(path, followLinks));
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | tests/standalone/io/file_invalid_arguments_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698