| OLD | NEW |
| 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 /// Helper functionality to make working with IO easier. | 5 /// Helper functionality to make working with IO easier. |
| 6 library pub.io; | 6 library pub.io; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 import 'dart:convert'; | 10 import 'dart:convert'; |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 executable = "cmd"; | 824 executable = "cmd"; |
| 825 } | 825 } |
| 826 | 826 |
| 827 log.process(executable, args, workingDir == null ? '.' : workingDir); | 827 log.process(executable, args, workingDir == null ? '.' : workingDir); |
| 828 | 828 |
| 829 return fn(executable, args, | 829 return fn(executable, args, |
| 830 workingDirectory: workingDir, | 830 workingDirectory: workingDir, |
| 831 environment: environment); | 831 environment: environment); |
| 832 } | 832 } |
| 833 | 833 |
| 834 /// Updates [path]'s modification time. |
| 835 void touch(String path) { |
| 836 var file = new File(path).openSync(mode: FileMode.APPEND); |
| 837 var originalLength = file.lengthSync(); |
| 838 file.writeByteSync(0); |
| 839 file.truncateSync(originalLength); |
| 840 file.closeSync(); |
| 841 } |
| 842 |
| 834 /// Creates a temporary directory and passes its path to [fn]. | 843 /// Creates a temporary directory and passes its path to [fn]. |
| 835 /// | 844 /// |
| 836 /// Once the [Future] returned by [fn] completes, the temporary directory and | 845 /// Once the [Future] returned by [fn] completes, the temporary directory and |
| 837 /// all its contents are deleted. [fn] can also return `null`, in which case | 846 /// all its contents are deleted. [fn] can also return `null`, in which case |
| 838 /// the temporary directory is deleted immediately afterwards. | 847 /// the temporary directory is deleted immediately afterwards. |
| 839 /// | 848 /// |
| 840 /// Returns a future that completes to the value that the future returned from | 849 /// Returns a future that completes to the value that the future returned from |
| 841 /// [fn] completes to. | 850 /// [fn] completes to. |
| 842 Future withTempDir(Future fn(String path)) { | 851 Future withTempDir(Future fn(String path)) { |
| 843 return new Future.sync(() { | 852 return new Future.sync(() { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 | 1060 |
| 1052 // TODO(rnystrom): Remove this and change to returning one string. | 1061 // TODO(rnystrom): Remove this and change to returning one string. |
| 1053 static List<String> _toLines(String output) { | 1062 static List<String> _toLines(String output) { |
| 1054 var lines = splitLines(output); | 1063 var lines = splitLines(output); |
| 1055 if (!lines.isEmpty && lines.last == "") lines.removeLast(); | 1064 if (!lines.isEmpty && lines.last == "") lines.removeLast(); |
| 1056 return lines; | 1065 return lines; |
| 1057 } | 1066 } |
| 1058 | 1067 |
| 1059 bool get success => exitCode == exit_codes.SUCCESS; | 1068 bool get success => exitCode == exit_codes.SUCCESS; |
| 1060 } | 1069 } |
| OLD | NEW |