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

Unified Diff: sdk/lib/_internal/pub/lib/src/command/cache_repair.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/command/cache_repair.dart
diff --git a/sdk/lib/_internal/pub/lib/src/command/cache_repair.dart b/sdk/lib/_internal/pub/lib/src/command/cache_repair.dart
new file mode 100644
index 0000000000000000000000000000000000000000..450951b238b2330d47351266e0f9a0f991d9dcd0
--- /dev/null
+++ b/sdk/lib/_internal/pub/lib/src/command/cache_repair.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library pub.command.cache_repair;
+
+import 'dart:async';
+
+import '../command.dart';
+import '../exit_codes.dart' as exit_codes;
+import '../io.dart';
+import '../log.dart' as log;
+import '../utils.dart';
+
+/// Handles the `cache repair` pub command.
+class CacheRepairCommand extends PubCommand {
+ String get description => "Reinstall cached packages.";
+ String get usage => "pub cache repair";
+ bool get requiresEntrypoint => false;
+
+ Future onRun() {
+ var successes = 0;
+ var failures = 0;
+
+ // Repair every cached source.
+ return Future.forEach(cache.sources.where(
+ (source) => source.shouldCache), (source) {
+ return source.repairCachedPackages().then((results) {
+ successes += results.first;
+ failures += results.last;
+ });
+ }).then((_) {
+ if (successes > 0) {
+ var packages = pluralize("package", successes);
+ log.message("Reinstalled ${log.green(successes)} $packages.");
+ }
+
+ if (failures > 0) {
+ var packages = pluralize("package", failures);
+ log.message("Failed to reinstall ${log.red(failures)} $packages.");
+ }
+
+ if (successes == 0 && failures == 0) {
+ log.message("No packages in cache, so nothing to repair.");
+ }
+
+ if (failures > 0) return flushThenExit(exit_codes.UNAVAILABLE);
+ });
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698