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

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

Issue 10970025: Beat on hosted repo support on Windows a bit more. (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 | « utils/pub/hosted_source.dart ('k') | utils/pub/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 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 checkComplete(); 504 checkComplete();
505 }; 505 };
506 506
507 process.onError = (error) => completer.completeException(error); 507 process.onError = (error) => completer.completeException(error);
508 508
509 return completer.future; 509 return completer.future;
510 } 510 }
511 511
512 /** 512 /**
513 * Wraps [input] to provide a timeout. If [input] completes before 513 * Wraps [input] to provide a timeout. If [input] completes before
514 * [milliSeconds] have passed, then the return value completes in the same way. 514 * [milliseconds] have passed, then the return value completes in the same way.
515 * However, if [milliSeconds] pass before [input] has completed, it completes 515 * However, if [milliseconds] pass before [input] has completed, it completes
516 * with a [TimeoutException] with [message]. 516 * with a [TimeoutException] with [message].
517 * 517 *
518 * Note that timing out will not cancel the asynchronous operation behind 518 * Note that timing out will not cancel the asynchronous operation behind
519 * [input]. 519 * [input].
520 */ 520 */
521 Future timeout(Future input, int milliSeconds, String message) { 521 Future timeout(Future input, int milliseconds, String message) {
522 var completer = new Completer(); 522 var completer = new Completer();
523 var timer = new Timer(milliSeconds, (_) { 523 var timer = new Timer(milliseconds, (_) {
524 if (completer.future.isComplete) return; 524 if (completer.future.isComplete) return;
525 completer.completeException(new TimeoutException(message)); 525 completer.completeException(new TimeoutException(message));
526 }); 526 });
527 input.handleException((e) { 527 input.handleException((e) {
528 if (completer.future.isComplete) return false; 528 if (completer.future.isComplete) return false;
529 timer.cancel(); 529 timer.cancel();
530 completer.completeException(e); 530 completer.completeException(e);
531 return true; 531 return true;
532 }); 532 });
533 input.then((value) { 533 input.then((value) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 stream.pipe(process.stdin); 621 stream.pipe(process.stdin);
622 process.stdout.pipe(stdout, close: false); 622 process.stdout.pipe(stdout, close: false);
623 process.stderr.pipe(stderr, close: false); 623 process.stderr.pipe(stderr, close: false);
624 }; 624 };
625 625
626 return completer.future.transform((exitCode) => exitCode == 0); 626 return completer.future.transform((exitCode) => exitCode == 0);
627 } 627 }
628 628
629 Future<bool> _extractTarGzWindows(InputStream stream, String destination) { 629 Future<bool> _extractTarGzWindows(InputStream stream, String destination) {
630 // Find 7zip. 630 // Find 7zip.
631 var scriptDir = new Path(new Options().script).directoryPath; 631 var scriptPath = new File(new Options().script).fullPathSync();
632 var scriptDir = new Path.fromNative(scriptPath).directoryPath;
632 633
633 // Note: This line of code gets munged by create_sdk.py to be the correct 634 // Note: This line of code gets munged by create_sdk.py to be the correct
634 // relative path to 7zip in the SDK. 635 // relative path to 7zip in the SDK.
635 var pathTo7zip = '../../third_party/7zip/7za.exe'; 636 var pathTo7zip = '../../third_party/7zip/7za.exe';
636 637
637 var command = scriptDir.append(pathTo7zip).canonicalize().toNativePath(); 638 var command = scriptDir.append(pathTo7zip).canonicalize().toNativePath();
638 639
639 // 7zip can't unarchive from gzip -> tar -> destination all in one step so 640 // 7zip can't unarchive from gzip -> tar -> destination all in one step so
640 // we spawn it twice and pipe them together. 641 // we spawn it twice and pipe them together.
641 var completer = new Completer<int>(); 642 var completer = new Completer<bool>();
642 var gzipProcess = Process.start(command, ["e", "-si", "-tgzip", '-so']); 643 var gzipProcess = Process.start(command, ['e', '-si', '-tgzip', '-so']);
644
645 // TODO(rnystrom): Even though we are quoting the destination directory here,
646 // 7zip still seems to barf if there is a space in the path. For now we'll
647 // just avoid spaces.
643 var tarProcess = Process.start(command, 648 var tarProcess = Process.start(command,
644 ["e", "-si", "-ttar", '-o"$destination"']); 649 ['x', '-si', '-ttar', '-o"$destination"']);
645 650
646 stream.pipe(gzipProcess.stdin); 651 // 7zip writes to stderr even when things are going OK, so we'll capture it
647 gzipProcess.stdout.pipe(tarProcess.stdin); 652 // here and only print it if the exit code is bad.
653 var errorStream = new ListOutputStream();
648 654
649 tarProcess.onExit = completer.complete; 655 // Wait for the process to be fully started before writing to its
650 gzipProcess.onError = completer.completeException; 656 // stdin stream.
657 gzipProcess.onStart = () {
658 stream.pipe(gzipProcess.stdin);
659 gzipProcess.stderr.pipe(errorStream, close: false);
660 };
661
662 tarProcess.onStart = () {
663 gzipProcess.stdout.pipe(tarProcess.stdin);
664 tarProcess.stderr.pipe(errorStream, close: false);
665
666 // TODO(rnystrom): For some mysterious reason, the extract hangs if you
667 // don't do this. Look into why.
668 tarProcess.stdout.pipe(new ListOutputStream());
669 };
670
671 tarProcess.onExit = (exitCode) {
672 if (exitCode != 0) {
673 printError(new String.fromCharCodes(errorStream.read()));
674 completer.completeException('Could not extract archive to $destination.');
675 } else {
676 completer.complete(true);
677 }
678 };
679
680 tarProcess.onError = completer.completeException;
651 gzipProcess.onError = completer.completeException; 681 gzipProcess.onError = completer.completeException;
652 682
653 return completer.future.transform((exitCode) => exitCode == 0); 683 return completer.future;
654 } 684 }
655 685
656 /** 686 /**
657 * Exception thrown when an HTTP operation fails. 687 * Exception thrown when an HTTP operation fails.
658 */ 688 */
659 class PubHttpException implements Exception { 689 class PubHttpException implements Exception {
660 final int statusCode; 690 final int statusCode;
661 final String reason; 691 final String reason;
662 692
663 const PubHttpException(this.statusCode, this.reason); 693 const PubHttpException(this.statusCode, this.reason);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 return new Directory(entry); 736 return new Directory(entry);
707 } 737 }
708 738
709 /** 739 /**
710 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. 740 * Gets a [Uri] for [uri], which can either already be one, or be a [String].
711 */ 741 */
712 Uri _getUri(uri) { 742 Uri _getUri(uri) {
713 if (uri is Uri) return uri; 743 if (uri is Uri) return uri;
714 return new Uri.fromString(uri); 744 return new Uri.fromString(uri);
715 } 745 }
OLDNEW
« no previous file with comments | « utils/pub/hosted_source.dart ('k') | utils/pub/pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698