| 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 /** | 5 /** |
| 6 * Helper functionality to make working with IO easier. | 6 * Helper functionality to make working with IO easier. |
| 7 */ | 7 */ |
| 8 library io; | 8 library io; |
| 9 | 9 |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 return true; | 528 return true; |
| 529 }); | 529 }); |
| 530 input.then((value) { | 530 input.then((value) { |
| 531 if (completer.future.isComplete) return; | 531 if (completer.future.isComplete) return; |
| 532 timer.cancel(); | 532 timer.cancel(); |
| 533 completer.complete(value); | 533 completer.complete(value); |
| 534 }); | 534 }); |
| 535 return completer.future; | 535 return completer.future; |
| 536 } | 536 } |
| 537 | 537 |
| 538 /// Creates a temporary directory and passes its path to [fn]. Once the [Future] |
| 539 /// returned by [fn] completes, the temporary directory and all its contents |
| 540 /// will be deleted. |
| 541 Future withTempDir(Future fn(String path)) { |
| 542 var tempDir; |
| 543 var future = new Directory('').createTemp().chain((dir) { |
| 544 tempDir = dir; |
| 545 return fn(tempDir.path); |
| 546 }); |
| 547 future.onComplete((_) => tempDir.delete(recursive: true)); |
| 548 return future; |
| 549 } |
| 550 |
| 538 /// Tests whether or not the git command-line app is available for use. | 551 /// Tests whether or not the git command-line app is available for use. |
| 539 Future<bool> get isGitInstalled { | 552 Future<bool> get isGitInstalled { |
| 540 if (_isGitInstalledCache != null) { | 553 if (_isGitInstalledCache != null) { |
| 541 // TODO(rnystrom): The sleep is to pump the message queue. Can use | 554 // TODO(rnystrom): The sleep is to pump the message queue. Can use |
| 542 // Future.immediate() when #3356 is fixed. | 555 // Future.immediate() when #3356 is fixed. |
| 543 return sleep(0).transform((_) => _isGitInstalledCache); | 556 return sleep(0).transform((_) => _isGitInstalledCache); |
| 544 } | 557 } |
| 545 | 558 |
| 546 return _gitCommand.transform((git) => git != null); | 559 return _gitCommand.transform((git) => git != null); |
| 547 } | 560 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 return new Directory(entry); | 759 return new Directory(entry); |
| 747 } | 760 } |
| 748 | 761 |
| 749 /** | 762 /** |
| 750 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 763 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 751 */ | 764 */ |
| 752 Uri _getUri(uri) { | 765 Uri _getUri(uri) { |
| 753 if (uri is Uri) return uri; | 766 if (uri is Uri) return uri; |
| 754 return new Uri.fromString(uri); | 767 return new Uri.fromString(uri); |
| 755 } | 768 } |
| OLD | NEW |