mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
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:
parent
88bb817a82
commit
55ad513b3b
3 changed files with 28 additions and 11 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue