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

Side by Side 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: Respond to review. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | utils/pub/io.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 library hosted_source; 5 library hosted_source;
6 6
7 import 'dart:io' as io; 7 import 'dart:io' as io;
8 import 'dart:json'; 8 import 'dart:json';
9 import 'dart:uri'; 9 import 'dart:uri';
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 /** 66 /**
67 * Downloads a package from the site and unpacks it. 67 * Downloads a package from the site and unpacks it.
68 */ 68 */
69 Future<bool> install(PackageId id, String destPath) { 69 Future<bool> install(PackageId id, String destPath) {
70 var parsedDescription = _parseDescription(id.description); 70 var parsedDescription = _parseDescription(id.description);
71 var name = parsedDescription.first; 71 var name = parsedDescription.first;
72 var url = parsedDescription.last; 72 var url = parsedDescription.last;
73 73
74 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz"; 74 var fullUrl = "$url/packages/$name/versions/${id.version}.tar.gz";
75 75
76 return Futures.wait([httpGet(fullUrl), ensureDir(destPath)]).chain((args) { 76 print('Downloading $id...');
77 return timeout(extractTarGz(args[0], args[1]), HTTP_TIMEOUT, 77
78 // Download and extract the archive to a temp directory.
79 var tempDir;
80 return Futures.wait([httpGet(fullUrl), createTempDir()]).chain((args) {
81 tempDir = args[1];
82 return timeout(extractTarGz(args[0], tempDir), HTTP_TIMEOUT,
78 'Timed out while fetching URL "$fullUrl".'); 83 'Timed out while fetching URL "$fullUrl".');
79 }).transformException((ex) { 84 }).chain((_) {
80 // If the install failed, delete the directory. Prevents leaving a ghost 85 // Now that the install has succeeded, move it to the real location in
81 // directory in the system cache which would later make pub think the 86 // the cache. This ensures that we don't leave half-busted ghost
82 // install succeeded. 87 // directories in the user's pub cache if an install fails.
83 // TODO(rnystrom): Use deleteDir() here when transformException() supports 88 return renameDir(tempDir, destPath);
84 // returning a future. Also remove dart:io import then. 89 }).transform((_) => true);
85 new io.Directory(destPath).deleteRecursivelySync();
86
87 throw ex;
88 });
89 } 90 }
90 91
91 /** 92 /**
92 * The system cache directory for the hosted source contains subdirectories 93 * The system cache directory for the hosted source contains subdirectories
93 * for each separate repository URL that's used on the system. Each of these 94 * for each separate repository URL that's used on the system. Each of these
94 * subdirectories then contains a subdirectory for each package installed 95 * subdirectories then contains a subdirectory for each package installed
95 * from that site. 96 * from that site.
96 */ 97 */
97 String systemCacheDirectory(PackageId id) { 98 String systemCacheDirectory(PackageId id) {
98 var parsed = _parseDescription(id.description); 99 var parsed = _parseDescription(id.description);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 143
143 var name = description["name"]; 144 var name = description["name"];
144 if (name is! String) { 145 if (name is! String) {
145 throw new FormatException("The 'name' key must have a string value."); 146 throw new FormatException("The 'name' key must have a string value.");
146 } 147 }
147 148
148 var url = description.containsKey("url") ? description["url"] : defaultUrl; 149 var url = description.containsKey("url") ? description["url"] : defaultUrl;
149 return new Pair<String, String>(name, url); 150 return new Pair<String, String>(name, url);
150 } 151 }
151 } 152 }
OLDNEW
« 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