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

Side by Side Diff: sdk/lib/io/file_system_entity.dart

Issue 14642012: dart:io | Add asynchronous versions of the methods of FileSystemEntity and Link. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add new async test file. Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | sdk/lib/io/link.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 class FileSystemEntityType { 7 class FileSystemEntityType {
8 static const FILE = const FileSystemEntityType._internal(0); 8 static const FILE = const FileSystemEntityType._internal(0);
9 static const DIRECTORY = const FileSystemEntityType._internal(1); 9 static const DIRECTORY = const FileSystemEntityType._internal(1);
10 static const LINK = const FileSystemEntityType._internal(2); 10 static const LINK = const FileSystemEntityType._internal(2);
(...skipping 25 matching lines...) Expand all
36 36
37 external static int _getType(String path, bool followLinks); 37 external static int _getType(String path, bool followLinks);
38 external static bool _identical(String path1, String path2); 38 external static bool _identical(String path1, String path2);
39 39
40 static int _getTypeSync(String path, bool followLinks) { 40 static int _getTypeSync(String path, bool followLinks) {
41 var result = _getType(path, followLinks); 41 var result = _getType(path, followLinks);
42 _throwIfError(result, 'Error getting type of FileSystemEntity'); 42 _throwIfError(result, 'Error getting type of FileSystemEntity');
43 return result; 43 return result;
44 } 44 }
45 45
46 static Future<int> _getTypeAsync(String path, bool followLinks) =>
47 new Future.sync(() => _getTypeSync(path, followLinks));
48
49 /**
50 * Do two paths refer to the same object in the file system?
51 * Links are not identical to their targets, and two links
52 * are not identical just because they point to identical targets.
53 * Links in intermediate directories in the paths are followed, though.
54 *
55 * Throws an error if one of the paths points to an object that does not
56 * exist.
57 * The target of a link can be compared by first getting it with Link.target.
58 */
59 static Future<bool> identical(String path1, String path2) {
60 var result = _identical(path1, path2);
61 _throwIfError(result, 'Error in FileSystemEntity.identical');
Bill Hesse 2013/05/02 14:02:42 Error should be on the future.
Bill Hesse 2013/05/02 14:02:42 Fixed - all errors are now on the Futures.
62 return new Future<bool>.value(result);
63 }
64
46 /** 65 /**
47 * Do two paths refer to the same object in the file system? 66 * Do two paths refer to the same object in the file system?
48 * Links are not identical to their targets, and two links 67 * Links are not identical to their targets, and two links
49 * are not identical just because they point to identical targets. 68 * are not identical just because they point to identical targets.
50 * Links in intermediate directories in the paths are followed, though. 69 * Links in intermediate directories in the paths are followed, though.
51 * 70 *
52 * Throws an error if one of the paths points to an object that does not 71 * Throws an error if one of the paths points to an object that does not
53 * exist. 72 * exist.
54 * The target of a link can be compared by first getting it with Link.target. 73 * The target of a link can be compared by first getting it with Link.target.
55 */ 74 */
56 static bool identicalSync(String path1, String path2) { 75 static bool identicalSync(String path1, String path2) {
57 var result = _identical(path1, path2); 76 var result = _identical(path1, path2);
58 _throwIfError(result, 'Error in FileSystemEntity.identical'); 77 _throwIfError(result, 'Error in FileSystemEntity.identical');
59 return result; 78 return result;
60 } 79 }
61 80
81 static Future<FileSystemEntityType> type(String path,
82 {bool followLinks: true})
83 => new Future<FileSystemEntityType>.value(
84 typeSync(path, followLinks: followLinks));
85
62 static FileSystemEntityType typeSync(String path, {bool followLinks: true}) 86 static FileSystemEntityType typeSync(String path, {bool followLinks: true})
63 => FileSystemEntityType._lookup(_getTypeSync(path, followLinks)); 87 => FileSystemEntityType._lookup(_getTypeSync(path, followLinks));
64 88
89 static Future<bool> isLink(String path) => _getTypeAsync(path, false).then(
90 (type) => (type == FileSystemEntityType.LINK._type));
91
92 static Future<bool> isFile(String path) => _getTypeAsync(path, true).then(
93 (type) => (type == FileSystemEntityType.FILE._type));
94
95 static Future<bool> isDirectory(String path) => _getTypeAsync(path, true)
96 .then((type) => (type == FileSystemEntityType.DIRECTORY._type));
97
65 static bool isLinkSync(String path) => 98 static bool isLinkSync(String path) =>
66 (_getTypeSync(path, false) == FileSystemEntityType.LINK._type); 99 (_getTypeSync(path, false) == FileSystemEntityType.LINK._type);
67 100
68 static bool isFileSync(String path) => 101 static bool isFileSync(String path) =>
69 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type); 102 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type);
70 103
71 static bool isDirectorySync(String path) => 104 static bool isDirectorySync(String path) =>
72 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); 105 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type);
73 106
74 static _throwIfError(Object result, String msg) { 107 static _throwIfError(Object result, String msg) {
75 if (result is OSError) { 108 if (result is OSError) {
76 throw new FileIOException(msg, result); 109 throw new FileIOException(msg, result);
77 } else if (result is ArgumentError) { 110 } else if (result is ArgumentError) {
78 throw result; 111 throw result;
79 } 112 }
80 } 113 }
81 } 114 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | sdk/lib/io/link.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698