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

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

Issue 11414044: Enable CurlClient tests on Windows by bundling curl.exe. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Really fix resource loading Created 8 years, 1 month 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
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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } else { 358 } else {
359 if (path.startsWith('/')) return path; 359 if (path.startsWith('/')) return path;
360 } 360 }
361 361
362 // Using Path.join here instead of File().fullPathSync() because the former 362 // Using Path.join here instead of File().fullPathSync() because the former
363 // does not require an actual file to exist at that path. 363 // does not require an actual file to exist at that path.
364 return new Path.fromNative(currentWorkingDir).join(new Path(path)) 364 return new Path.fromNative(currentWorkingDir).join(new Path(path))
365 .toNativePath(); 365 .toNativePath();
366 } 366 }
367 367
368 /// Resolves [path] relative to the location of pub.dart.
369 String relativeToPub(String path) {
370 var scriptPath = new File(new Options().script).fullPathSync();
371 var scriptDir = new Path.fromNative(scriptPath).directoryPath;
372 return scriptDir.append(path).canonicalize().toNativePath();
373 }
374
368 // TODO(nweiz): make this configurable 375 // TODO(nweiz): make this configurable
369 /** 376 /**
370 * The amount of time in milliseconds to allow HTTP requests before assuming 377 * The amount of time in milliseconds to allow HTTP requests before assuming
371 * they've failed. 378 * they've failed.
372 */ 379 */
373 final HTTP_TIMEOUT = 30 * 1000; 380 final HTTP_TIMEOUT = 30 * 1000;
374 381
375 /** 382 /**
376 * Opens an input stream for a HTTP GET request to [uri], which may be a 383 * Opens an input stream for a HTTP GET request to [uri], which may be a
377 * [String] or [Uri]. 384 * [String] or [Uri].
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 } 646 }
640 647
641 Future<bool> _extractTarGzWindows(InputStream stream, String destination) { 648 Future<bool> _extractTarGzWindows(InputStream stream, String destination) {
642 // TODO(rnystrom): In the repo's history, there is an older implementation of 649 // TODO(rnystrom): In the repo's history, there is an older implementation of
643 // this that does everything in memory by piping streams directly together 650 // this that does everything in memory by piping streams directly together
644 // instead of writing out temp files. The code is simpler, but unfortunately, 651 // instead of writing out temp files. The code is simpler, but unfortunately,
645 // 7zip seems to periodically fail when we invoke it from Dart and tell it to 652 // 7zip seems to periodically fail when we invoke it from Dart and tell it to
646 // read from stdin instead of a file. Consider resurrecting that version if 653 // read from stdin instead of a file. Consider resurrecting that version if
647 // we can figure out why it fails. 654 // we can figure out why it fails.
648 655
649 // Find 7zip.
650 var scriptPath = new File(new Options().script).fullPathSync();
651 var scriptDir = new Path.fromNative(scriptPath).directoryPath;
652
653 // Note: This line of code gets munged by create_sdk.py to be the correct 656 // Note: This line of code gets munged by create_sdk.py to be the correct
654 // relative path to 7zip in the SDK. 657 // relative path to 7zip in the SDK.
655 var pathTo7zip = '../../third_party/7zip/7za.exe'; 658 var pathTo7zip = '../../third_party/7zip/7za.exe';
656 var command = scriptDir.append(pathTo7zip).canonicalize().toNativePath(); 659 var command = relativeToPub(pathTo7zip);
657 660
658 var tempDir; 661 var tempDir;
659 662
660 return createTempDir().chain((temp) { 663 return createTempDir().chain((temp) {
661 // Write the archive to a temp file. 664 // Write the archive to a temp file.
662 tempDir = temp; 665 tempDir = temp;
663 return createFileFromStream(stream, join(tempDir, 'data.tar.gz')); 666 return createFileFromStream(stream, join(tempDir, 'data.tar.gz'));
664 }).chain((_) { 667 }).chain((_) {
665 // 7zip can't unarchive from gzip -> tar -> destination all in one step 668 // 7zip can't unarchive from gzip -> tar -> destination all in one step
666 // first we un-gzip it to a tar file. 669 // first we un-gzip it to a tar file.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 return new Directory(entry); 762 return new Directory(entry);
760 } 763 }
761 764
762 /** 765 /**
763 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. 766 * Gets a [Uri] for [uri], which can either already be one, or be a [String].
764 */ 767 */
765 Uri _getUri(uri) { 768 Uri _getUri(uri) {
766 if (uri is Uri) return uri; 769 if (uri is Uri) return uri;
767 return new Uri.fromString(uri); 770 return new Uri.fromString(uri);
768 } 771 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698