Index: sdk/lib/_internal/pub/lib/src/global_packages.dart |
diff --git a/sdk/lib/_internal/pub/lib/src/global_packages.dart b/sdk/lib/_internal/pub/lib/src/global_packages.dart |
index eb4864f0fc8f75b6f0d796cce2a631748d929a2f..6b29cd2e7ca8916c1e5d347fb3fc28ddea3efa7f 100644 |
--- a/sdk/lib/_internal/pub/lib/src/global_packages.dart |
+++ b/sdk/lib/_internal/pub/lib/src/global_packages.dart |
@@ -10,6 +10,7 @@ import 'dart:io'; |
import 'package:path/path.dart' as p; |
+import 'entrypoint.dart'; |
import 'io.dart'; |
import 'lock_file.dart'; |
import 'log.dart' as log; |
@@ -50,13 +51,11 @@ class GlobalPackages { |
/// Finds the latest version of the hosted package with [name] that matches |
/// [constraint] and makes it the active global version. |
Future activate(String name, VersionConstraint constraint) { |
- var lockFilePath = p.join(_directory, name + ".lock"); |
- |
// See if we already have it activated. |
var lockFile; |
var currentVersion; |
try { |
- lockFile = new LockFile.load(lockFilePath, cache.sources); |
+ lockFile = new LockFile.load(_getLockFilePath(name), cache.sources); |
currentVersion = lockFile.packages[name].version; |
// Pull the root package out of the lock file so the solver doesn't see |
@@ -66,7 +65,7 @@ class GlobalPackages { |
log.message("Package ${log.bold(name)} is already active at " |
"version ${log.bold(currentVersion)}."); |
} on IOException catch (error) { |
- // If we couldn't read the lock and version file, it's not activated. |
+ // If we couldn't read the lock file, it's not activated. |
lockFile = new LockFile.empty(); |
} |
@@ -98,7 +97,7 @@ class GlobalPackages { |
lockFile.packages[name] = id; |
ensureDir(_directory); |
- writeTextFile(lockFilePath, |
+ writeTextFile(_getLockFilePath(name), |
lockFile.serialize(cache.rootDir, cache.sources)); |
log.message("Activated ${log.bold(package.name)} ${package.version}."); |
@@ -123,6 +122,34 @@ class GlobalPackages { |
} |
} |
+ /// Finds the active packge with [name]. |
+ /// |
+ /// Returns an [Entrypoint] loaded with the active package if found. |
+ Future<Entrypoint> find(String name) { |
+ var lockFile; |
+ var version; |
+ return syncFuture(() { |
+ try { |
+ lockFile = new LockFile.load(_getLockFilePath(name), cache.sources); |
+ version = lockFile.packages[name].version; |
+ } |
+ on IOException catch (error) { |
nweiz
2014/07/02 00:12:02
Nit: move this to the previous line.
Bob Nystrom
2014/07/02 18:00:53
Done.
|
+ // If we couldn't read the lock file, it's not activated. |
+ dataError("No active package ${log.bold(name)}."); |
+ } |
+ }).then((_) { |
+ // Load the package from the cache. |
+ var id = new PackageId(name, _source.name, version, name); |
+ return _source.downloadToSystemCache(id); |
nweiz
2014/07/02 00:12:02
It reads very weird that this is "downloadToSystem
Bob Nystrom
2014/07/02 18:00:53
downloadToSystemCache conveniently handles loading
|
+ }).then((package) { |
+ // Pull the root package out of the lock file so the solver doesn't see |
+ // it. |
+ lockFile.packages.remove(name); |
+ |
+ return new Entrypoint.inMemory(package, lockFile, cache); |
+ }); |
+ } |
+ |
/// Picks the best version of [package] to activate that meets [constraint]. |
/// |
/// If [version] is not `null`, this tries to maintain that version if |
@@ -149,4 +176,7 @@ class GlobalPackages { |
return versions.last; |
}); |
} |
+ |
+ /// Gets the path to the lock file for an activated package with [name]. |
+ String _getLockFilePath(name) => p.join(_directory, name + ".lock"); |
} |