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

Unified Diff: utils/pub/hosted_source.dart

Issue 11151026: Download to a temp dir and rename on success. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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') | utils/pub/io.dart » ('J')
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 330ca5b5fc1b13f0efe3f2a85870ce890b6a7312..ecffcab5b64147db3ae6d718de377faeb5663668 100644
--- a/utils/pub/hosted_source.dart
+++ b/utils/pub/hosted_source.dart
@@ -73,19 +73,20 @@ class HostedSource extends Source {
var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz";
- return Futures.wait([httpGet(fullUrl), ensureDir(destPath)]).chain((args) {
- return timeout(extractTarGz(args[0], args[1]), HTTP_TIMEOUT,
- 'Timed out while fetching URL "$fullUrl".');
- }).transformException((ex) {
- // If the install failed, delete the directory. Prevents leaving a ghost
- // directory in the system cache which would later make pub think the
- // install succeeded.
- // TODO(rnystrom): Use deleteDir() here when transformException() supports
- // returning a future. Also remove dart:io import then.
- new io.Directory(destPath).deleteRecursivelySync();
+ print('Downloading $id...');
- throw ex;
- });
+ // Download and extract the archive to a temp directory.
+ var tempDir;
+ return Futures.wait([httpGet(fullUrl), createTempDir()]).chain((args) {
+ tempDir = args[1];
+ return timeout(extractTarGz(args[0], tempDir), HTTP_TIMEOUT,
+ 'Timed out while fetching URL "$fullUrl".');
+ }).chain((_) {
+ // 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);
+ }).transform((_) => true);
}
/**
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | utils/pub/io.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698