OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /// Helper functionality to make working with IO easier. | 5 /// Helper functionality to make working with IO easier. |
6 library io; | 6 library io; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 } | 52 } |
53 | 53 |
54 /// Returns the path to [target] from [base]. | 54 /// Returns the path to [target] from [base]. |
55 String relativeTo(target, base) => path.relative(target, from: base); | 55 String relativeTo(target, base) => path.relative(target, from: base); |
56 | 56 |
57 /// Asynchronously determines if [path], which can be a [String] file path, a | 57 /// Asynchronously determines if [path], which can be a [String] file path, a |
58 /// [File], or a [Directory] exists on the file system. Returns a [Future] that | 58 /// [File], or a [Directory] exists on the file system. Returns a [Future] that |
59 /// completes with the result. | 59 /// completes with the result. |
60 Future<bool> exists(path) { | 60 Future<bool> exists(path) { |
61 path = _getPath(path); | 61 path = _getPath(path); |
62 return Futures.wait([fileExists(path), dirExists(path)]).then((results) { | 62 return Future.wait([fileExists(path), dirExists(path)]).then((results) { |
63 return results[0] || results[1]; | 63 return results[0] || results[1]; |
64 }); | 64 }); |
65 } | 65 } |
66 | 66 |
67 /// Asynchronously determines if [file], which can be a [String] file path or a | 67 /// Asynchronously determines if [file], which can be a [String] file path or a |
68 /// [File], exists on the file system. Returns a [Future] that completes with | 68 /// [File], exists on the file system. Returns a [Future] that completes with |
69 /// the result. | 69 /// the result. |
70 Future<bool> fileExists(file) { | 70 Future<bool> fileExists(file) { |
71 var path = _getPath(file); | 71 var path = _getPath(file); |
72 return log.ioAsync("Seeing if file $path exists.", | 72 return log.ioAsync("Seeing if file $path exists.", |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 if (recursive) { | 277 if (recursive) { |
278 children.add(doList(new Directory(file), listedDirectories)); | 278 children.add(doList(new Directory(file), listedDirectories)); |
279 } | 279 } |
280 }; | 280 }; |
281 lister.onFile = (file) { | 281 lister.onFile = (file) { |
282 if (!includeHiddenFiles && basename(file).startsWith('.')) return; | 282 if (!includeHiddenFiles && basename(file).startsWith('.')) return; |
283 contents.add(join(dir, basename(file))); | 283 contents.add(join(dir, basename(file))); |
284 }; | 284 }; |
285 | 285 |
286 return completer.future.then((contents) { | 286 return completer.future.then((contents) { |
287 return Futures.wait(children).then((childContents) { | 287 return Future.wait(children).then((childContents) { |
288 contents.addAll(flatten(childContents)); | 288 contents.addAll(flatten(childContents)); |
289 return contents; | 289 return contents; |
290 }); | 290 }); |
291 }); | 291 }); |
292 } | 292 } |
293 | 293 |
294 return doList(_getDirectory(dir), new Set<String>()); | 294 return doList(_getDirectory(dir), new Set<String>()); |
295 } | 295 } |
296 | 296 |
297 /// Asynchronously determines if [dir], which can be a [String] directory path | 297 /// Asynchronously determines if [dir], which can be a [String] directory path |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 Directory _getDirectory(entry) { | 1028 Directory _getDirectory(entry) { |
1029 if (entry is Directory) return entry; | 1029 if (entry is Directory) return entry; |
1030 return new Directory(entry); | 1030 return new Directory(entry); |
1031 } | 1031 } |
1032 | 1032 |
1033 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1033 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
1034 Uri _getUri(uri) { | 1034 Uri _getUri(uri) { |
1035 if (uri is Uri) return uri; | 1035 if (uri is Uri) return uri; |
1036 return new Uri.fromString(uri); | 1036 return new Uri.fromString(uri); |
1037 } | 1037 } |
OLD | NEW |