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

Side by Side Diff: sdk/lib/_internal/pub_generated/lib/src/source/hosted.dart

Issue 745153002: Make pub's binstubs resilient to changes in snapshot format. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years 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 library pub.source.hosted; 5 library pub.source.hosted;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 import "dart:convert"; 9 import "dart:convert";
10 10
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 /// refers to a package with the given name from the host at the given URL. 122 /// refers to a package with the given name from the host at the given URL.
123 dynamic parseDescription(String containingPath, description, 123 dynamic parseDescription(String containingPath, description,
124 {bool fromLockFile: false}) { 124 {bool fromLockFile: false}) {
125 _parseDescription(description); 125 _parseDescription(description);
126 return description; 126 return description;
127 } 127 }
128 128
129 /// Re-downloads all packages that have been previously downloaded into the 129 /// Re-downloads all packages that have been previously downloaded into the
130 /// system cache from any server. 130 /// system cache from any server.
131 Future<Pair<int, int>> repairCachedPackages() { 131 Future<Pair<int, int>> repairCachedPackages() {
132 if (!dirExists(systemCacheRoot)) return new Future.value(new Pair(0, 0)); 132 final completer0 = new Completer();
133 133 scheduleMicrotask(() {
134 var successes = 0; 134 try {
135 var failures = 0; 135 join0() {
136 136 var successes = 0;
137 return Future.wait(listDir(systemCacheRoot).map((serverDir) { 137 var failures = 0;
138 var url = _directoryToUrl(path.basename(serverDir)); 138 var it0 = listDir(systemCacheRoot).iterator;
139 var packages = _getCachedPackagesInDirectory(path.basename(serverDir)); 139 break0() {
140 packages.sort(Package.orderByNameAndVersion); 140 completer0.complete(new Pair(successes, failures));
141 return Future.wait(packages.map((package) { 141 }
142 return _download( 142 var trampoline0;
143 url, 143 continue0() {
144 package.name, 144 trampoline0 = null;
145 package.version, 145 if (it0.moveNext()) {
146 package.dir).then((_) { 146 var serverDir = it0.current;
147 successes++; 147 var url = _directoryToUrl(path.basename(serverDir));
148 }).catchError((error, stackTrace) { 148 var packages =
149 failures++; 149 _getCachedPackagesInDirectory(path.basename(serverDir));
150 var message = 150 packages.sort(Package.orderByNameAndVersion);
151 "Failed to repair ${log.bold(package.name)} " "${package.version}" ; 151 var it1 = packages.iterator;
152 if (url != defaultUrl) message += " from $url"; 152 break1() {
153 log.error("$message. Error:\n$error"); 153 trampoline0 = continue0;
154 log.fine(stackTrace); 154 }
155 }); 155 var trampoline1;
156 })); 156 continue1() {
157 })).then((_) => new Pair(successes, failures)); 157 trampoline1 = null;
158 if (it1.moveNext()) {
159 var package = it1.current;
160 join1() {
161 trampoline1 = continue1;
162 }
163 catch0(error, stackTrace) {
164 try {
165 failures++;
166 var message =
167 "Failed to repair ${log.bold(package.name)} " "${packa ge.version}";
168 join2() {
169 log.error("${message}. Error:\n${error}");
170 log.fine(stackTrace);
171 tryDeleteEntry(package.dir);
172 join1();
173 }
174 if (url != defaultUrl) {
175 message += " from ${url}";
176 join2();
177 } else {
178 join2();
179 }
180 } catch (error, stackTrace) {
181 completer0.completeError(error, stackTrace);
182 }
183 }
184 try {
185 _download(
186 url,
187 package.name,
188 package.version,
189 package.dir).then((x0) {
190 trampoline1 = () {
191 trampoline1 = null;
192 try {
193 x0;
194 successes++;
195 join1();
196 } catch (e0, s0) {
197 catch0(e0, s0);
198 }
199 };
200 do trampoline1(); while (trampoline1 != null);
201 }, onError: catch0);
202 } catch (e1, s1) {
203 catch0(e1, s1);
204 }
205 } else {
206 break1();
207 }
208 }
209 trampoline1 = continue1;
210 do trampoline1(); while (trampoline1 != null);
211 } else {
212 break0();
213 }
214 }
215 trampoline0 = continue0;
216 do trampoline0(); while (trampoline0 != null);
217 }
218 if (!dirExists(systemCacheRoot)) {
219 completer0.complete(new Pair(0, 0));
220 } else {
221 join0();
222 }
223 } catch (e, s) {
224 completer0.completeError(e, s);
225 }
226 });
227 return completer0.future;
158 } 228 }
159 229
160 /// Gets all of the packages that have been downloaded into the system cache 230 /// Gets all of the packages that have been downloaded into the system cache
161 /// from the default server. 231 /// from the default server.
162 List<Package> getCachedPackages() { 232 List<Package> getCachedPackages() {
163 return _getCachedPackagesInDirectory(_urlToDirectory(defaultUrl)); 233 return _getCachedPackagesInDirectory(_urlToDirectory(defaultUrl));
164 } 234 }
165 235
166 /// Gets all of the packages that have been downloaded into the system cache 236 /// Gets all of the packages that have been downloaded into the system cache
167 /// into [dir]. 237 /// into [dir].
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 var name = description["name"]; 442 var name = description["name"];
373 if (name is! String) { 443 if (name is! String) {
374 throw new FormatException("The 'name' key must have a string value."); 444 throw new FormatException("The 'name' key must have a string value.");
375 } 445 }
376 446
377 var url = description["url"]; 447 var url = description["url"];
378 if (url == null) url = HostedSource.defaultUrl; 448 if (url == null) url = HostedSource.defaultUrl;
379 449
380 return new Pair<String, String>(name, url); 450 return new Pair<String, String>(name, url);
381 } 451 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698