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

Unified Diff: sdk/lib/_internal/pub/lib/src/source.dart

Issue 228703006: Add “pub cache repair” to forcibly re-install previously cached packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise. Created 6 years, 8 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
Index: sdk/lib/_internal/pub/lib/src/source.dart
diff --git a/sdk/lib/_internal/pub/lib/src/source.dart b/sdk/lib/_internal/pub/lib/src/source.dart
index 2927cc4b8ec797aac4be1733336b2360f9559591..06181c5197a5ee46803b9e9ac5e5fbc074b48a5b 100644
--- a/sdk/lib/_internal/pub/lib/src/source.dart
+++ b/sdk/lib/_internal/pub/lib/src/source.dart
@@ -160,16 +160,25 @@ abstract class Source {
///
/// This is only called for sources with [shouldCache] set to true. By
/// default, this uses [systemCacheDirectory] and [get].
- Future<Package> downloadToSystemCache(PackageId id) {
+ ///
+ /// If [force] is `true`, then the package is downloaded even if it already
+ /// exists in the cache. The previous one will be deleted.
+ Future<Package> downloadToSystemCache(PackageId id, {bool force}) {
+ if (force == null) force = false;
+
var packageDir;
return systemCacheDirectory(id).then((p) {
packageDir = p;
// See if it's already cached.
if (dirExists(packageDir)) {
- if (!_isCachedPackageCorrupted(packageDir)) return true;
- // Busted, so wipe out the package and re-download.
- deleteEntry(packageDir);
+ if (force || _isCachedPackageCorrupted(packageDir)) {
+ // Wipe it out and re-install it.
+ deleteEntry(packageDir);
+ } else {
+ // Already downloaded.
+ return true;
+ }
}
ensureDir(path.dirname(packageDir));
@@ -220,6 +229,19 @@ abstract class Source {
new Chain.current());
}
+ /// Reinstalls all packages that have been previously installed into the
+ /// system cache by this source.
+ ///
+ /// Returns a [Pair] whose first element is the number of packages
+ /// successfully repaired and the second is the number of failures.
+ Future<Pair<int, int>> repairCachedPackages() {
+ if (shouldCache) {
+ throw new UnimplementedError("Source $name must implement this.");
+ }
+ throw new UnsupportedError("Cannot call repairCachedPackages() on an "
+ "uncached source.");
+ }
+
/// When a [Pubspec] or [LockFile] is parsed, it reads in the description for
/// each dependency. It is up to the dependency's [Source] to determine how
/// that should be interpreted. This will be called during parsing to validate

Powered by Google App Engine
This is Rietveld 408576698