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

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

Issue 10947031: Fix use of Process API in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months 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 | « no previous file | utils/tests/pub/pub.status » ('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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 }; 374 };
375 375
376 connection.onResponse = (response) { 376 connection.onResponse = (response) {
377 if (response.statusCode >= 400) { 377 if (response.statusCode >= 400) {
378 client.shutdown(); 378 client.shutdown();
379 completer.completeException( 379 completer.completeException(
380 new HttpException(response.statusCode, response.reasonPhrase)); 380 new HttpException(response.statusCode, response.reasonPhrase));
381 return; 381 return;
382 } 382 }
383 383
384 // TODO(nweiz): remove this extra pipe when issue 4974 is fixed. 384 completer.complete(response.inputStream);
385 var sink = new ListInputStream();
386 pipeInputToInput(response.inputStream, sink);
387 completer.complete(sink);
388 }; 385 };
389 386
390 return completer.future; 387 return completer.future;
391 } 388 }
392 389
393 /** 390 /**
394 * Opens an input stream for a HTTP GET request to [uri], which may be a 391 * Opens an input stream for a HTTP GET request to [uri], which may be a
395 * [String] or [Uri]. Completes with the result of the request as a String. 392 * [String] or [Uri]. Completes with the result of the request as a String.
396 */ 393 */
397 Future<String> httpGetString(uri) { 394 Future<String> httpGetString(uri) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 576
580 /** 577 /**
581 * Extracts a `.tar.gz` file from [stream] to [destination], which can be a 578 * Extracts a `.tar.gz` file from [stream] to [destination], which can be a
582 * directory or a path. Returns whether or not the extraction was successful. 579 * directory or a path. Returns whether or not the extraction was successful.
583 */ 580 */
584 Future<bool> extractTarGz(InputStream stream, destination) { 581 Future<bool> extractTarGz(InputStream stream, destination) {
585 var process = Process.start("tar", 582 var process = Process.start("tar",
586 ["--extract", "--gunzip", "--directory", _getPath(destination)]); 583 ["--extract", "--gunzip", "--directory", _getPath(destination)]);
587 var completer = new Completer<int>(); 584 var completer = new Completer<int>();
588 585
589 stream.pipe(process.stdin); 586 // Wait for the process to be fully started before writing to its
590 process.stdout.pipe(stdout, close: false); 587 // stdin stream.
591 process.stderr.pipe(stderr, close: false); 588 process.onStart = () {
589 stream.pipe(process.stdin);
590 process.stdout.pipe(stdout, close: false);
591 process.stderr.pipe(stderr, close: false);
592 592
593 process.onExit = completer.complete; 593 process.onExit = completer.complete;
594 process.onError = completer.completeException; 594 process.onError = completer.completeException;
nweiz 2012/09/19 18:09:45 What happens if "tar" isn't found? Will onStart fi
Mads Ager (google) 2012/09/20 06:16:26 Good catch, thanks! If the executable is not found
595 };
596
595 return completer.future.transform((exitCode) => exitCode == 0); 597 return completer.future.transform((exitCode) => exitCode == 0);
596 } 598 }
597 599
598 /** 600 /**
599 * Exception thrown when an HTTP operation fails. 601 * Exception thrown when an HTTP operation fails.
600 */ 602 */
601 class HttpException implements Exception { 603 class HttpException implements Exception {
602 final int statusCode; 604 final int statusCode;
603 final String reason; 605 final String reason;
604 606
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 return new Directory(entry); 650 return new Directory(entry);
649 } 651 }
650 652
651 /** 653 /**
652 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. 654 * Gets a [Uri] for [uri], which can either already be one, or be a [String].
653 */ 655 */
654 Uri _getUri(uri) { 656 Uri _getUri(uri) {
655 if (uri is Uri) return uri; 657 if (uri is Uri) return uri;
656 return new Uri.fromString(uri); 658 return new Uri.fromString(uri);
657 } 659 }
OLDNEW
« no previous file with comments | « no previous file | utils/tests/pub/pub.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698