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

Unified Diff: lib/src/source/hosted.dart

Issue 1459733002: Move pubspec caching into each source. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 5 years, 1 month 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 | « lib/src/source.dart ('k') | lib/src/validator/dependency.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/source/hosted.dart
diff --git a/lib/src/source/hosted.dart b/lib/src/source/hosted.dart
index ded6e8dae3164cfb2911e6aa1f665e19a33c895f..0179c151cdd33270a246a038bb1ab1d88076f01b 100644
--- a/lib/src/source/hosted.dart
+++ b/lib/src/source/hosted.dart
@@ -37,8 +37,8 @@ class HostedSource extends CachedSource {
/// Downloads a list of all versions of a package that are available from the
/// site.
- Future<List<Pubspec>> getVersions(String name, description) async {
- var url = _makeUrl(description,
+ Future<List<PackageId>> doGetVersions(PackageRef ref) async {
+ var url = _makeUrl(ref.description,
(server, package) => "$server/api/packages/$package");
log.io("Get versions from $url.");
@@ -47,15 +47,19 @@ class HostedSource extends CachedSource {
try {
body = await httpClient.read(url, headers: PUB_API_HEADERS);
} catch (error, stackTrace) {
- var parsed = _parseDescription(description);
+ var parsed = _parseDescription(ref.description);
_throwFriendlyError(error, stackTrace, parsed.first, parsed.last);
}
var doc = JSON.decode(body);
return doc['versions'].map((map) {
- return new Pubspec.fromMap(
+ var pubspec = new Pubspec.fromMap(
map['pubspec'], systemCache.sources,
- expectedName: name, location: url);
+ expectedName: ref.name, location: url);
+ var id = ref.atVersion(pubspec.version);
+ memoizePubspec(id, pubspec);
+
+ return id;
}).toList();
}
@@ -223,21 +227,30 @@ class HostedSource extends CachedSource {
/// This uses the system cache to get the list of available packages and does
/// no network access.
class OfflineHostedSource extends HostedSource {
- /// Gets the list of all versions of [name] that are in the system cache.
- Future<List<Pubspec>> getVersions(String name, description) async {
- var parsed = _parseDescription(description);
+ /// Gets the list of all versions of [ref] that are in the system cache.
+ Future<List<PackageId>> doGetVersions(PackageRef ref) async {
+ var parsed = _parseDescription(ref.description);
var server = parsed.last;
- log.io("Finding versions of $name in "
+ log.io("Finding versions of ${ref.name} in "
"$systemCacheRoot/${_urlToDirectory(server)}");
- var versions = await _getCachedPackagesInDirectory(_urlToDirectory(server))
- .where((package) => package.name == name)
- .map((package) => package.pubspec)
- .toList();
+
+ var dir = path.join(systemCacheRoot, _urlToDirectory(server));
+
+ var versions;
+ if (dirExists(dir)) {
+ versions = await listDir(dir).map((entry) {
+ var components = path.basename(entry).split("-");
+ if (components.first != ref.name) return null;
+ return ref.atVersion(new Version.parse(components.last));
+ }).where((id) => id != null).toList();
+ } else {
+ versions = [];
+ }
// If there are no versions in the cache, report a clearer error.
if (versions.isEmpty) {
throw new PackageNotFoundException(
- "Could not find package $name in cache.");
+ "Could not find package ${ref.name} in cache.");
}
return versions;
« no previous file with comments | « lib/src/source.dart ('k') | lib/src/validator/dependency.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698