Chromium Code Reviews| Index: utils/pub/hosted_source.dart |
| diff --git a/utils/pub/hosted_source.dart b/utils/pub/hosted_source.dart |
| index bd017e667a61f48e912f40600dcbede85071d10a..103ea5eb7363a07076cfd72e709c7c24095309c5 100644 |
| --- a/utils/pub/hosted_source.dart |
| +++ b/utils/pub/hosted_source.dart |
| @@ -49,15 +49,23 @@ 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"); |
| + 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"))) { |
| + return new Pubspec.load(id.name, cacheDir, systemCache.sources); |
|
nweiz
2013/04/18 22:50:03
We should catch format/IO errors, print a warning,
Bob Nystrom
2013/04/18 23:07:10
Done.
|
| + } |
| - 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); |
| + // 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) { |
|
nweiz
2013/04/18 22:50:03
Add a TODO to cache these pubspecs as well. We pro
Bob Nystrom
2013/04/18 23:07:10
Done.
|
| + return new Pubspec.parse(null, yaml, systemCache.sources); |
| + }).catchError((ex) { |
| + var parsed = _parseDescription(id.description); |
| + _throwFriendlyError(ex, id, parsed.last); |
| + }); |
| }); |
| } |
| @@ -122,11 +130,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. |