Chromium Code Reviews| Index: utils/pub/system_cache.dart |
| diff --git a/utils/pub/system_cache.dart b/utils/pub/system_cache.dart |
| index 1e26554cd72a177088c1a83779d6940b07e50b1d..3c7df3e357225c0807bbe02d650497056979407d 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,28 @@ 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) { |
|
nweiz
2013/01/31 22:38:53
I don't like that this returns a Package whereas o
Bob Nystrom
2013/02/01 16:53:29
I had that originally, but Pubspec doesn't know ho
nweiz
2013/02/01 22:24:54
I think it's fine to use Package internally to loa
Bob Nystrom
2013/02/02 00:02:31
Done.
|
| + Future<Package> getUncached() { |
| + // Not cached, so get it from the source. |
| + return id.source.describe(id).then((pubspec) { |
|
nweiz
2013/01/31 22:38:53
"id.source.describe(id)" -> "id.describe()"
Bob Nystrom
2013/02/01 16:53:29
Done.
|
| + return new Package.inMemory(pubspec); |
| + }); |
| + } |
| + |
| + // Try to get it from the system cache first. |
| + if (id.source.shouldCache) { |
| + return id.source.systemCacheDirectory(id).then((packageDir) { |
|
nweiz
2013/01/31 22:38:53
This would be a little cleaner with an "id.systemC
Bob Nystrom
2013/02/01 16:53:29
Done.
|
| + 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. |
| /// |