| Index: utils/pub/source.dart
|
| diff --git a/utils/pub/source.dart b/utils/pub/source.dart
|
| index 21144ce3ea8c56405cce0d50bc4db5993d20c866..236aa9a5eb2897c8637bbfa3ccf42805cb957c61 100644
|
| --- a/utils/pub/source.dart
|
| +++ b/utils/pub/source.dart
|
| @@ -95,15 +95,42 @@ class Source {
|
| *
|
| * [path] is guaranteed not to exist, and its parent directory is guaranteed
|
| * to exist.
|
| + *
|
| + * This doesn't need to be implemented if [installToSystemCache] is
|
| + * implemented.
|
| */
|
| - abstract Future<bool> install(PackageId id, String path);
|
| + Future<bool> install(PackageId id, String path) {
|
| + throw "Either install or installToSystemCache must be implemented for "
|
| + "source $name."
|
| + }
|
| +
|
| + /**
|
| + * Installs the package identified by [id] to the system cache. This is only
|
| + * called for sources with [shouldCache] set to true.
|
| + *
|
| + * By default, this uses [systemCacheDirectory] and [install].
|
| + */
|
| + Future<Package> installToSystemCache(PackageId id) {
|
| + var path = systemCacheDirectory(id);
|
| + return exists(path).chain((exists) {
|
| + // TODO(nweiz): better error handling
|
| + if (exists) throw 'Package $id is already installed.';
|
| + return ensureDir(dirname(path));
|
| + }).chain((_) {
|
| + return install(id, path);
|
| + }).chain((found) {
|
| + if (!found) throw 'Package $id not found.';
|
| + return Package.load(path, systemCache.sources);
|
| + });
|
| + }
|
|
|
| /**
|
| * Returns the directory in the system cache that the package identified by
|
| * [id] should be installed to. This should return a path to a subdirectory of
|
| * [systemCacheRoot].
|
| *
|
| - * This doesn't need to be implemented if [shouldCache] is false.
|
| + * This doesn't need to be implemented if [shouldCache] is false, or if
|
| + * [installToSystemCache] is implemented.
|
| */
|
| String systemCacheDirectory(PackageId id) =>
|
| join(systemCacheRoot, packageName(id.description));
|
|
|