| 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 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 // TODO: Unrequired wrapper, stdout is now an EventSink<List<int>>. | 292 // TODO: Unrequired wrapper, stdout is now an EventSink<List<int>>. |
| 293 final EventSink<List<int>> stderrSink = _wrapStdio(stderr, "stderr"); | 293 final EventSink<List<int>> stderrSink = _wrapStdio(stderr, "stderr"); |
| 294 | 294 |
| 295 /// Wrap the standard output or error [stream] in a [EventSink]. Any errors are | 295 /// Wrap the standard output or error [stream] in a [EventSink]. Any errors are |
| 296 /// logged, and then the program is terminated. [name] is used for debugging. | 296 /// logged, and then the program is terminated. [name] is used for debugging. |
| 297 EventSink<List<int>> _wrapStdio(IOSink sink, String name) { | 297 EventSink<List<int>> _wrapStdio(IOSink sink, String name) { |
| 298 var pair = consumerToSink(sink); | 298 var pair = consumerToSink(sink); |
| 299 pair.last.catchError((e) { | 299 pair.last.catchError((e) { |
| 300 // This log may or may not work, depending on how the stream failed. Not | 300 // This log may or may not work, depending on how the stream failed. Not |
| 301 // much we can do about that. | 301 // much we can do about that. |
| 302 log.error("Error writing to $name: $e"); | 302 log.error("Error writing to $name", e); |
| 303 exit(exit_codes.IO); | 303 exit(exit_codes.IO); |
| 304 }); | 304 }); |
| 305 return pair.first; | 305 return pair.first; |
| 306 } | 306 } |
| 307 | 307 |
| 308 /// A line-by-line stream of standard input. | 308 /// A line-by-line stream of standard input. |
| 309 final Stream<String> stdinLines = streamToLines( | 309 final Stream<String> stdinLines = streamToLines( |
| 310 new ByteStream(stdin).toStringStream()); | 310 new ByteStream(stdin).toStringStream()); |
| 311 | 311 |
| 312 /// Displays a message and reads a yes/no confirmation from the user. Returns | 312 /// Displays a message and reads a yes/no confirmation from the user. Returns |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 var args = ["--create", "--gzip", "--directory", baseDir]; | 663 var args = ["--create", "--gzip", "--directory", baseDir]; |
| 664 args.addAll(contents); | 664 args.addAll(contents); |
| 665 // TODO(nweiz): It's possible that enough command-line arguments will make | 665 // TODO(nweiz): It's possible that enough command-line arguments will make |
| 666 // the process choke, so at some point we should save the arguments to a | 666 // the process choke, so at some point we should save the arguments to a |
| 667 // file and pass them in via --files-from for tar and -i@filename for 7zip. | 667 // file and pass them in via --files-from for tar and -i@filename for 7zip. |
| 668 startProcess("tar", args).then((process) { | 668 startProcess("tar", args).then((process) { |
| 669 store(process.stdout, controller); | 669 store(process.stdout, controller); |
| 670 }).catchError((e) { | 670 }).catchError((e) { |
| 671 // We don't have to worry about double-signaling here, since the store() | 671 // We don't have to worry about double-signaling here, since the store() |
| 672 // above will only be reached if startProcess succeeds. | 672 // above will only be reached if startProcess succeeds. |
| 673 controller.addError(e.error, e.stackTrace); | 673 controller.addError(e); |
| 674 controller.close(); | 674 controller.close(); |
| 675 }); | 675 }); |
| 676 return new ByteStream(controller.stream); | 676 return new ByteStream(controller.stream); |
| 677 } | 677 } |
| 678 | 678 |
| 679 withTempDir((tempDir) { | 679 withTempDir((tempDir) { |
| 680 // Create the tar file. | 680 // Create the tar file. |
| 681 var tarFile = path.join(tempDir, "intermediate.tar"); | 681 var tarFile = path.join(tempDir, "intermediate.tar"); |
| 682 var args = ["a", "-w$baseDir", tarFile]; | 682 var args = ["a", "-w$baseDir", tarFile]; |
| 683 args.addAll(contents.map((entry) => '-i!"$entry"')); | 683 args.addAll(contents.map((entry) => '-i!"$entry"')); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 700 // Ignore 7zip's stderr. 7zip writes its normal output to stderr. We don't | 700 // Ignore 7zip's stderr. 7zip writes its normal output to stderr. We don't |
| 701 // want to show that since it's meaningless. | 701 // want to show that since it's meaningless. |
| 702 // | 702 // |
| 703 // TODO(rnystrom): Should log the stderr and display it if an actual error | 703 // TODO(rnystrom): Should log the stderr and display it if an actual error |
| 704 // occurs. | 704 // occurs. |
| 705 return store(process.stdout, controller); | 705 return store(process.stdout, controller); |
| 706 }); | 706 }); |
| 707 }).catchError((e) { | 707 }).catchError((e) { |
| 708 // We don't have to worry about double-signaling here, since the store() | 708 // We don't have to worry about double-signaling here, since the store() |
| 709 // above will only be reached if everything succeeds. | 709 // above will only be reached if everything succeeds. |
| 710 controller.addError(e.error, e.stackTrace); | 710 controller.addError(e); |
| 711 controller.close(); | 711 controller.close(); |
| 712 }); | 712 }); |
| 713 return new ByteStream(controller.stream); | 713 return new ByteStream(controller.stream); |
| 714 } | 714 } |
| 715 | 715 |
| 716 /// Exception thrown when an operation times out. | 716 /// Exception thrown when an operation times out. |
| 717 class TimeoutException implements Exception { | 717 class TimeoutException implements Exception { |
| 718 final String message; | 718 final String message; |
| 719 | 719 |
| 720 const TimeoutException(this.message); | 720 const TimeoutException(this.message); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 731 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 731 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
| 732 | 732 |
| 733 bool get success => exitCode == 0; | 733 bool get success => exitCode == 0; |
| 734 } | 734 } |
| 735 | 735 |
| 736 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 736 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 737 Uri _getUri(uri) { | 737 Uri _getUri(uri) { |
| 738 if (uri is Uri) return uri; | 738 if (uri is Uri) return uri; |
| 739 return Uri.parse(uri); | 739 return Uri.parse(uri); |
| 740 } | 740 } |
| OLD | NEW |