| 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 | 27 for (var source in cache.sources.all.map(cache.source)) { |
| 28 .map((source) => cache.source(source.name))) { | |
| 29 if (source is! CachedSource) continue; | 28 if (source is! CachedSource) continue; |
| 30 | 29 |
| 31 var results = await source.repairCachedPackages(); | 30 var results = await source.repairCachedPackages(); |
| 32 successes.addAll(results.first); | 31 successes.addAll(results.first); |
| 33 failures.addAll(results.last); | 32 failures.addAll(results.last); |
| 34 } | 33 } |
| 35 | 34 |
| 36 if (successes.length > 0) { | 35 if (successes.length > 0) { |
| 37 var packages = pluralize("package", successes.length); | 36 var packages = pluralize("package", successes.length); |
| 38 log.message("Reinstalled ${log.green(successes.length)} $packages."); | 37 log.message("Reinstalled ${log.green(successes.length)} $packages."); |
| 39 } | 38 } |
| 40 | 39 |
| 41 if (failures.length > 0) { | 40 if (failures.length > 0) { |
| 42 var packages = pluralize("package", failures.length); | 41 var packages = pluralize("package", failures.length); |
| 43 var buffer = new StringBuffer( | 42 var buffer = new StringBuffer( |
| 44 "Failed to reinstall ${log.red(failures.length)} $packages:\n"); | 43 "Failed to reinstall ${log.red(failures.length)} $packages:\n"); |
| 45 | 44 |
| 46 for (var id in failures) { | 45 for (var id in failures) { |
| 47 buffer.write("- ${log.bold(id.name)} ${id.version}"); | 46 buffer.write("- ${log.bold(id.name)} ${id.version}"); |
| 48 if (cache.sources[id.source] != cache.sources.defaultSource) { | 47 if (id.source != cache.sources.defaultSource) { |
| 49 buffer.write(" from ${id.source}"); | 48 buffer.write(" from ${id.source}"); |
| 50 } | 49 } |
| 51 buffer.writeln(); | 50 buffer.writeln(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 log.message(buffer.toString()); | 53 log.message(buffer.toString()); |
| 55 } | 54 } |
| 56 | 55 |
| 57 var results = await globals.repairActivatedPackages(); | 56 var results = await globals.repairActivatedPackages(); |
| 58 if (results.first.length > 0) { | 57 if (results.first.length > 0) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 | 68 |
| 70 if (successes.length == 0 && failures.length == 0) { | 69 if (successes.length == 0 && failures.length == 0) { |
| 71 log.message("No packages in cache, so nothing to repair."); | 70 log.message("No packages in cache, so nothing to repair."); |
| 72 } | 71 } |
| 73 | 72 |
| 74 if (failures.length > 0 || results.last.length > 0) { | 73 if (failures.length > 0 || results.last.length > 0) { |
| 75 await flushThenExit(exit_codes.UNAVAILABLE); | 74 await flushThenExit(exit_codes.UNAVAILABLE); |
| 76 } | 75 } |
| 77 } | 76 } |
| 78 } | 77 } |
| OLD | NEW |