| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import '../command.dart'; | 7 import '../command.dart'; |
| 8 import '../exit_codes.dart' as exit_codes; | 8 import '../exit_codes.dart' as exit_codes; |
| 9 import '../io.dart'; | 9 import '../io.dart'; |
| 10 import '../log.dart' as log; | 10 import '../log.dart' as log; |
| 11 import '../source/cached.dart'; | 11 import '../source/cached.dart'; |
| 12 import '../utils.dart'; | 12 import '../utils.dart'; |
| 13 | 13 |
| 14 /// Handles the `cache repair` pub command. | 14 /// Handles the `cache repair` pub command. |
| 15 class CacheRepairCommand extends PubCommand { | 15 class CacheRepairCommand extends PubCommand { |
| 16 String get name => "repair"; | 16 String get name => "repair"; |
| 17 String get description => "Reinstall cached packages."; | 17 String get description => "Reinstall cached packages."; |
| 18 String get invocation => "pub cache repair"; | 18 String get invocation => "pub cache repair"; |
| 19 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-cache.html"; | 19 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-cache.html"; |
| 20 bool get takesArguments => false; | 20 bool get takesArguments => false; |
| 21 | 21 |
| 22 Future run() async { | 22 Future run() async { |
| 23 var successes = []; | 23 var successes = []; |
| 24 var failures = []; | 24 var failures = []; |
| 25 | 25 |
| 26 // Repair every cached source. | 26 // Repair every cached source. |
| 27 for (var source in cache.sources.all.map(cache.source)) { | 27 for (var source in cache.sources.all.map(cache.source)) { |
| 28 if (source is! CachedSource) continue; | 28 if (source is CachedSource) { |
| 29 | 29 var results = await source.repairCachedPackages(); |
| 30 var results = await source.repairCachedPackages(); | 30 successes.addAll(results.first); |
| 31 successes.addAll(results.first); | 31 failures.addAll(results.last); |
| 32 failures.addAll(results.last); | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 if (successes.length > 0) { | 35 if (successes.length > 0) { |
| 36 var packages = pluralize("package", successes.length); | 36 var packages = pluralize("package", successes.length); |
| 37 log.message("Reinstalled ${log.green(successes.length)} $packages."); | 37 log.message("Reinstalled ${log.green(successes.length)} $packages."); |
| 38 } | 38 } |
| 39 | 39 |
| 40 if (failures.length > 0) { | 40 if (failures.length > 0) { |
| 41 var packages = pluralize("package", failures.length); | 41 var packages = pluralize("package", failures.length); |
| 42 var buffer = new StringBuffer( | 42 var buffer = new StringBuffer( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 68 | 68 |
| 69 if (successes.length == 0 && failures.length == 0) { | 69 if (successes.length == 0 && failures.length == 0) { |
| 70 log.message("No packages in cache, so nothing to repair."); | 70 log.message("No packages in cache, so nothing to repair."); |
| 71 } | 71 } |
| 72 | 72 |
| 73 if (failures.length > 0 || results.last.length > 0) { | 73 if (failures.length > 0 || results.last.length > 0) { |
| 74 await flushThenExit(exit_codes.UNAVAILABLE); | 74 await flushThenExit(exit_codes.UNAVAILABLE); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 } | 77 } |
| OLD | NEW |