Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: utils/pub/io.dart

Issue 11470030: Work around issue 7218 in Pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Bug fixes. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/pub/curl_client.dart ('k') | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 } 639 }
640 640
641 /// Spawns the process located at [executable], passing in [args]. Returns a 641 /// Spawns the process located at [executable], passing in [args]. Returns a
642 /// [Future] that will complete with the [Process] once it's been started. 642 /// [Future] that will complete with the [Process] once it's been started.
643 /// 643 ///
644 /// The spawned process will inherit its parent's environment variables. If 644 /// The spawned process will inherit its parent's environment variables. If
645 /// [environment] is provided, that will be used to augment (not replace) the 645 /// [environment] is provided, that will be used to augment (not replace) the
646 /// the inherited variables. 646 /// the inherited variables.
647 Future<Process> startProcess(String executable, List<String> args, 647 Future<Process> startProcess(String executable, List<String> args,
648 {workingDir, Map<String, String> environment}) => 648 {workingDir, Map<String, String> environment}) =>
649 _doProcess(Process.start, executable, args, workingDir, environment); 649 _doProcess(Process.start, executable, args, workingDir, environment)
650 .transform((process) => new _WrappedProcess(process));
651
652 /// A wrapper around [Process] that buffers the stdout and stderr to avoid
653 /// running into issue 7218.
654 class _WrappedProcess implements Process {
655 final Process _process;
656 final InputStream stderr;
657 final InputStream stdout;
658
659 OutputStream get stdin => _process.stdin;
660
661 void set onExit(void callback(int exitCode)) {
662 _process.onExit = callback;
663 }
664
665 _WrappedProcess(Process process)
666 : _process = process,
667 stderr = wrapInputStream(process.stderr),
668 stdout = wrapInputStream(process.stdout);
669
670 bool kill([ProcessSignal signal = ProcessSignal.SIGTERM]) =>
671 _process.kill(signal);
672 }
650 673
651 /// Calls [fn] with appropriately modified arguments. [fn] should have the same 674 /// Calls [fn] with appropriately modified arguments. [fn] should have the same
652 /// signature as [Process.start], except that the returned [Future] may have a 675 /// signature as [Process.start], except that the returned [Future] may have a
653 /// type other than [Process]. 676 /// type other than [Process].
654 Future _doProcess(Function fn, String executable, List<String> args, workingDir, 677 Future _doProcess(Function fn, String executable, List<String> args, workingDir,
655 Map<String, String> environment) { 678 Map<String, String> environment) {
656 // TODO(rnystrom): Should dart:io just handle this? 679 // TODO(rnystrom): Should dart:io just handle this?
657 // Spawning a process on Windows will not look for the executable in the 680 // Spawning a process on Windows will not look for the executable in the
658 // system path. So, if executable looks like it needs that (i.e. it doesn't 681 // system path. So, if executable looks like it needs that (i.e. it doesn't
659 // have any path separators in it), then spawn it through a shell. 682 // have any path separators in it), then spawn it through a shell.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 * directory or a path. Returns whether or not the extraction was successful. 835 * directory or a path. Returns whether or not the extraction was successful.
813 */ 836 */
814 Future<bool> extractTarGz(InputStream stream, destination) { 837 Future<bool> extractTarGz(InputStream stream, destination) {
815 destination = _getPath(destination); 838 destination = _getPath(destination);
816 839
817 if (Platform.operatingSystem == "windows") { 840 if (Platform.operatingSystem == "windows") {
818 return _extractTarGzWindows(stream, destination); 841 return _extractTarGzWindows(stream, destination);
819 } 842 }
820 843
821 var completer = new Completer<int>(); 844 var completer = new Completer<int>();
822 var processFuture = Process.start("tar", 845 var processFuture = startProcess("tar",
823 ["--extract", "--gunzip", "--directory", destination]); 846 ["--extract", "--gunzip", "--directory", destination]);
824 processFuture.then((process) { 847 processFuture.then((process) {
825 process.onExit = completer.complete; 848 process.onExit = completer.complete;
826 stream.pipe(process.stdin); 849 stream.pipe(process.stdin);
827 process.stdout.pipe(stdout, close: false); 850 process.stdout.pipe(stdout, close: false);
828 process.stderr.pipe(stderr, close: false); 851 process.stderr.pipe(stderr, close: false);
829 }); 852 });
830 processFuture.handleException((error) { 853 processFuture.handleException((error) {
831 completer.completeException(error, processFuture.stackTrace); 854 completer.completeException(error, processFuture.stackTrace);
832 return true; 855 return true;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 return new Directory(entry); 1052 return new Directory(entry);
1030 } 1053 }
1031 1054
1032 /** 1055 /**
1033 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. 1056 * Gets a [Uri] for [uri], which can either already be one, or be a [String].
1034 */ 1057 */
1035 Uri _getUri(uri) { 1058 Uri _getUri(uri) {
1036 if (uri is Uri) return uri; 1059 if (uri is Uri) return uri;
1037 return new Uri.fromString(uri); 1060 return new Uri.fromString(uri);
1038 } 1061 }
OLDNEW
« no previous file with comments | « utils/pub/curl_client.dart ('k') | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698