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

Unified Diff: utils/pub/hosted_source.dart

Issue 12225085: Make createTempDir() synchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/hosted_source.dart
diff --git a/utils/pub/hosted_source.dart b/utils/pub/hosted_source.dart
index 2db9cc8ab34226abd77f14d90a845b7ea786ddca..ef56462d37b9003fe078853b37c8621b624fb0b2 100644
--- a/utils/pub/hosted_source.dart
+++ b/utils/pub/hosted_source.dart
@@ -62,31 +62,29 @@ class HostedSource extends Source {
/// Downloads a package from the site and unpacks it.
Future<bool> install(PackageId id, String destPath) {
- var parsedDescription = _parseDescription(id.description);
- var name = parsedDescription.first;
- var url = parsedDescription.last;
-
- var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz";
-
- log.message('Downloading $id...');
-
- // Download and extract the archive to a temp directory.
- var tempDir;
- return Future.wait([
- httpClient.send(new http.Request("GET", Uri.parse(fullUrl)))
- .then((response) => response.stream),
- systemCache.createTempDir()
- ]).then((args) {
- var stream = args[0];
- tempDir = args[1];
- return timeout(extractTarGz(stream, tempDir), HTTP_TIMEOUT,
- 'fetching URL "$fullUrl"');
- }).then((_) {
- // Now that the install has succeeded, move it to the real location in
- // the cache. This ensures that we don't leave half-busted ghost
- // directories in the user's pub cache if an install fails.
- return renameDir(tempDir, destPath);
- }).then((_) => true);
+ return defer(() {
+ var parsedDescription = _parseDescription(id.description);
+ var name = parsedDescription.first;
+ var url = parsedDescription.last;
+
+ var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz";
+
+ log.message('Downloading $id...');
+
+ // Download and extract the archive to a temp directory.
+ var tempDir = systemCache.createTempDir();
+ return httpClient.send(new http.Request("GET", Uri.parse(fullUrl)))
+ .then((response) => response.stream)
+ .then((stream) {
+ return timeout(extractTarGz(stream, tempDir), HTTP_TIMEOUT,
+ 'fetching URL "$fullUrl"');
+ }).then((_) {
+ // Now that the install has succeeded, move it to the real location in
+ // the cache. This ensures that we don't leave half-busted ghost
+ // directories in the user's pub cache if an install fails.
+ return renameDir(tempDir, destPath);
+ }).then((_) => true);
+ });
}
/// The system cache directory for the hosted source contains subdirectories
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698