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 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 completer.completeError(e.error, e.stackTrace); | 742 completer.completeError(e.error, e.stackTrace); |
743 }); | 743 }); |
744 return completer.future; | 744 return completer.future; |
745 } | 745 } |
746 | 746 |
747 /// Creates a temporary directory and passes its path to [fn]. Once the [Future] | 747 /// Creates a temporary directory and passes its path to [fn]. Once the [Future] |
748 /// returned by [fn] completes, the temporary directory and all its contents | 748 /// returned by [fn] completes, the temporary directory and all its contents |
749 /// will be deleted. | 749 /// will be deleted. |
750 Future withTempDir(Future fn(String path)) { | 750 Future withTempDir(Future fn(String path)) { |
751 var tempDir; | 751 var tempDir; |
752 return asyncWhenComplete(createTempDir().then((dir) { | 752 return createTempDir().then((dir) { |
753 tempDir = dir; | 753 tempDir = dir; |
754 return fn(tempDir.path); | 754 return fn(tempDir.path); |
755 }), () { | 755 }).whenComplete(() { |
756 log.fine('Cleaning up temp directory ${tempDir.path}.'); | 756 log.fine('Cleaning up temp directory ${tempDir.path}.'); |
757 return deleteDir(tempDir); | 757 return deleteDir(tempDir); |
758 }); | 758 }); |
759 } | 759 } |
760 | 760 |
761 /// Tests whether or not the git command-line app is available for use. | 761 /// Tests whether or not the git command-line app is available for use. |
762 Future<bool> get isGitInstalled { | 762 Future<bool> get isGitInstalled { |
763 if (_isGitInstalledCache != null) { | 763 if (_isGitInstalledCache != null) { |
764 // TODO(rnystrom): The sleep is to pump the message queue. Can use | 764 // TODO(rnystrom): The sleep is to pump the message queue. Can use |
765 // Future.immediate() when #3356 is fixed. | 765 // Future.immediate() when #3356 is fixed. |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 Directory _getDirectory(entry) { | 1017 Directory _getDirectory(entry) { |
1018 if (entry is Directory) return entry; | 1018 if (entry is Directory) return entry; |
1019 return new Directory(entry); | 1019 return new Directory(entry); |
1020 } | 1020 } |
1021 | 1021 |
1022 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1022 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
1023 Uri _getUri(uri) { | 1023 Uri _getUri(uri) { |
1024 if (uri is Uri) return uri; | 1024 if (uri is Uri) return uri; |
1025 return new Uri.fromString(uri); | 1025 return new Uri.fromString(uri); |
1026 } | 1026 } |
OLD | NEW |