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

Unified Diff: utils/pub/system_cache.dart

Issue 12092080: Validate packages against their SDK constraints. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 7 years, 11 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 | « utils/pub/source.dart ('k') | utils/pub/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/system_cache.dart
diff --git a/utils/pub/system_cache.dart b/utils/pub/system_cache.dart
index 1e26554cd72a177088c1a83779d6940b07e50b1d..634dc173257b0e9742a549f86e6903fae9b855be 100644
--- a/utils/pub/system_cache.dart
+++ b/utils/pub/system_cache.dart
@@ -13,6 +13,7 @@ import 'io.dart';
import 'io.dart' as io show createTempDir;
import 'log.dart' as log;
import 'package.dart';
+import 'pubspec.dart';
import 'sdk_source.dart';
import 'source.dart';
import 'source_registry.dart';
@@ -59,6 +60,26 @@ class SystemCache {
sources.register(source);
}
+ /// Gets the package identified by [id]. If the package is already cached,
+ /// reads it from the cache. Otherwise, requests it from the source.
+ Future<Package> describe(PackageId id) {
+ Future<Package> getUncached() {
+ // Not cached, so get it from the source.
+ return id.describe().then((pubspec) => new Package.inMemory(pubspec));
+ }
+
+ // Try to get it from the system cache first.
+ if (id.source.shouldCache) {
+ return id.systemCacheDirectory.then((packageDir) {
+ if (!dirExistsSync(packageDir)) return getUncached();
+ return Package.load(id.name, packageDir, sources);
+ });
+ }
+
+ // Not cached, so get it from the source.
+ return getUncached();
+ }
+
/// Ensures that the package identified by [id] is installed to the cache,
/// loads it, and returns it.
///
« no previous file with comments | « utils/pub/source.dart ('k') | utils/pub/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698