Work around issue 7218 in Pub.

Review URL: https://codereview.chromium.org//11470030

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@15878 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
nweiz@google.com 2012-12-08 03:21:15 +00:00
parent 88bb817a82
commit 55ad513b3b
3 changed files with 28 additions and 11 deletions

View file

@ -39,7 +39,7 @@ class CurlClient extends http.BaseClient {
var arguments = _argumentsForRequest(request, headerFile);
log.process(executable, arguments);
var process;
return Process.start(executable, arguments).chain((process_) {
return startProcess(executable, arguments).chain((process_) {
process = process_;
if (requestStream.closed) {
process.stdin.close();

View file

@ -712,7 +712,30 @@ Future<PubProcessResult> runProcess(String executable, List<String> args,
/// the inherited variables.
Future<Process> startProcess(String executable, List<String> args,
{workingDir, Map<String, String> environment}) =>
_doProcess(Process.start, executable, args, workingDir, environment);
_doProcess(Process.start, executable, args, workingDir, environment)
.transform((process) => new _WrappedProcess(process));
/// A wrapper around [Process] that buffers the stdout and stderr to avoid
/// running into issue 7218.
class _WrappedProcess implements Process {
final Process _process;
final InputStream stderr;
final InputStream stdout;
OutputStream get stdin => _process.stdin;
void set onExit(void callback(int exitCode)) {
_process.onExit = callback;
}
_WrappedProcess(Process process)
: _process = process,
stderr = wrapInputStream(process.stderr),
stdout = wrapInputStream(process.stdout);
bool kill([ProcessSignal signal = ProcessSignal.SIGTERM]) =>
_process.kill(signal);
}
/// Calls [fn] with appropriately modified arguments. [fn] should have the same
/// signature as [Process.start], except that the returned [Future] may have a
@ -892,7 +915,7 @@ Future<bool> extractTarGz(InputStream stream, destination) {
}
var completer = new Completer<int>();
var processFuture = Process.start("tar",
var processFuture = startProcess("tar",
["--extract", "--gunzip", "--directory", destination]);
processFuture.then((process) {
process.onExit = completer.complete;

View file

@ -1334,8 +1334,8 @@ class ScheduledProcess {
/// Wraps a [Process] [Future] in a scheduled process.
ScheduledProcess(this.name, Future<Process> process)
: _process = process,
_stdout = process.transform((p) => _wrapStream(p.stdout)),
_stderr = process.transform((p) => _wrapStream(p.stderr)) {
_stdout = process.transform((p) => new StringInputStream(p.stdout)),
_stderr = process.transform((p) => new StringInputStream(p.stderr)) {
_schedule((_) {
if (!_endScheduled) {
@ -1466,12 +1466,6 @@ class ScheduledProcess {
});
}
/// Wraps [source] and ensures it gets eagerly drained. We do this to make
/// sure a process will exit even if we don't care about its output.
static StringInputStream _wrapStream(InputStream source) {
return new StringInputStream(wrapInputStream(source));
}
/// Prints the remaining data in the process's stdout and stderr streams.
/// Prints nothing if the straems are empty.
Future _printStreams() {