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

Unified Diff: utils/pub/hosted_source.dart

Issue 14241005: Use the cached pubspec if possible for describing hosted packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 8 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/tests/pub/test_pub.dart » ('j') | utils/tests/pub/test_pub.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 bd017e667a61f48e912f40600dcbede85071d10a..b8d08123ba960894fef756c88298b981f5194dfb 100644
--- a/utils/pub/hosted_source.dart
+++ b/utils/pub/hosted_source.dart
@@ -49,15 +49,33 @@ class HostedSource extends Source {
/// Downloads and parses the pubspec for a specific version of a package that
/// is available from the site.
Future<Pubspec> describe(PackageId id) {
- var url = _makeVersionUrl(id, (server, package, version) =>
- "$server/packages/$package/versions/$version.yaml");
-
- log.io("Describe package at $url.");
- return httpClient.read(url).then((yaml) {
- return new Pubspec.parse(null, yaml, systemCache.sources);
- }).catchError((ex) {
- var parsed = _parseDescription(id.description);
- _throwFriendlyError(ex, id, parsed.last);
+ return systemCacheDirectory(id).then((cacheDir) {
+ // See if we already have it in the cache. If so, just load it locally.
+ if (fileExists(path.join(cacheDir, "pubspec.yaml"))) {
+ try {
+ return new Pubspec.load(id.name, cacheDir, systemCache.sources);
+ } on FormatException catch(error) {
nweiz 2013/04/19 00:12:31 Nit: space between "catch" and "(error)". We shou
+ // If the cached pubspec is corrupted for some reason, don't use it
+ // and instead continue and request it from the server.
+ log.fine("Cached pubspec for $id had format error:\n$error");
nweiz 2013/04/19 00:12:31 Print the stack trace as well.
+ }
+ }
+
+ // Request it from the server.
+ var url = _makeVersionUrl(id, (server, package, version) =>
+ "$server/packages/$package/versions/$version.yaml");
+
+ log.io("Describe package at $url.");
+ return httpClient.read(url).then((yaml) {
+ // TODO(rnystrom): After this is pulled down, we could place it in
+ // a secondary cache of just pubspecs. This would let us have a
+ // persistent cache for pubspecs for packages that haven't actually
+ // been installed.
+ return new Pubspec.parse(null, yaml, systemCache.sources);
+ }).catchError((ex) {
+ var parsed = _parseDescription(id.description);
+ _throwFriendlyError(ex, id, parsed.last);
+ });
});
}
@@ -122,11 +140,11 @@ class HostedSource extends Source {
var cacheDir = path.join(systemCacheRoot,
_getSourceDirectory(_defaultUrl));
if (!dirExists(cacheDir)) return [];
-
+
return listDir(path.join(cacheDir)).map((entry) =>
new Package.load(null, entry, systemCache.sources)).toList();
}
-
+
/// When an error occurs trying to read something about [package] from [url],
/// this tries to translate into a more user friendly error message. Always
/// throws an error, either the original one or a better one.
« no previous file with comments | « no previous file | utils/tests/pub/test_pub.dart » ('j') | utils/tests/pub/test_pub.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698