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

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: Address comments 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(() => _getTypeSync(path, followLinks));
48
46 /** 49 /**
47 * Do two paths refer to the same object in the file system? 50 * Do two paths refer to the same object in the file system?
48 * Links are not identical to their targets, and two links 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 new Future<bool>(() => identicalSync(path1, path2));
61
62 /**
63 * Do two paths refer to the same object in the file system?
64 * Links are not identical to their targets, and two links
49 * are not identical just because they point to identical targets. 65 * are not identical just because they point to identical targets.
50 * Links in intermediate directories in the paths are followed, though. 66 * Links in intermediate directories in the paths are followed, though.
51 * 67 *
52 * Throws an error if one of the paths points to an object that does not 68 * Throws an error if one of the paths points to an object that does not
53 * exist. 69 * exist.
54 * The target of a link can be compared by first getting it with Link.target. 70 * The target of a link can be compared by first getting it with Link.target.
55 */ 71 */
56 static bool identicalSync(String path1, String path2) { 72 static bool identicalSync(String path1, String path2) {
57 var result = _identical(path1, path2); 73 var result = _identical(path1, path2);
58 _throwIfError(result, 'Error in FileSystemEntity.identical'); 74 _throwIfError(result, 'Error in FileSystemEntity.identical');
59 return result; 75 return result;
60 } 76 }
61 77
78 static Future<FileSystemEntityType> type(String path,
79 {bool followLinks: true})
80 => new Future<FileSystemEntityType>(
81 () => typeSync(path, followLinks: followLinks));
82
62 static FileSystemEntityType typeSync(String path, {bool followLinks: true}) 83 static FileSystemEntityType typeSync(String path, {bool followLinks: true})
63 => FileSystemEntityType._lookup(_getTypeSync(path, followLinks)); 84 => FileSystemEntityType._lookup(_getTypeSync(path, followLinks));
64 85
86 static Future<bool> isLink(String path) => _getTypeAsync(path, false)
87 .then((type) => (type == FileSystemEntityType.LINK._type));
88
89 static Future<bool> isFile(String path) => _getTypeAsync(path, true)
90 .then((type) => (type == FileSystemEntityType.FILE._type));
91
92 static Future<bool> isDirectory(String path) => _getTypeAsync(path, true)
93 .then((type) => (type == FileSystemEntityType.DIRECTORY._type));
94
65 static bool isLinkSync(String path) => 95 static bool isLinkSync(String path) =>
66 (_getTypeSync(path, false) == FileSystemEntityType.LINK._type); 96 (_getTypeSync(path, false) == FileSystemEntityType.LINK._type);
67 97
68 static bool isFileSync(String path) => 98 static bool isFileSync(String path) =>
69 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type); 99 (_getTypeSync(path, true) == FileSystemEntityType.FILE._type);
70 100
71 static bool isDirectorySync(String path) => 101 static bool isDirectorySync(String path) =>
72 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type); 102 (_getTypeSync(path, true) == FileSystemEntityType.DIRECTORY._type);
73 103
74 static _throwIfError(Object result, String msg) { 104 static _throwIfError(Object result, String msg) {
75 if (result is OSError) { 105 if (result is OSError) {
76 throw new FileIOException(msg, result); 106 throw new FileIOException(msg, result);
77 } else if (result is ArgumentError) { 107 } else if (result is ArgumentError) {
78 throw result; 108 throw result;
79 } 109 }
80 } 110 }
81 } 111 }
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