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 library pub.command.cache_repair; | 5 library pub.command.cache_repair; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import '../command.dart'; | 9 import '../command.dart'; |
10 import '../exit_codes.dart' as exit_codes; | 10 import '../exit_codes.dart' as exit_codes; |
11 import '../io.dart'; | 11 import '../io.dart'; |
12 import '../log.dart' as log; | 12 import '../log.dart' as log; |
13 import '../source/cached.dart'; | 13 import '../source/cached.dart'; |
14 import '../utils.dart'; | 14 import '../utils.dart'; |
15 | 15 |
16 /// Handles the `cache repair` pub command. | 16 /// Handles the `cache repair` pub command. |
17 class CacheRepairCommand extends PubCommand { | 17 class CacheRepairCommand extends PubCommand { |
18 String get name => "repair"; | 18 String get name => "repair"; |
19 String get description => "Reinstall cached packages."; | 19 String get description => "Reinstall cached packages."; |
20 String get invocation => "pub cache repair"; | 20 String get invocation => "pub cache repair"; |
21 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-cache.html"; | 21 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-cache.html"; |
22 bool get takesArguments => false; | 22 bool get takesArguments => false; |
23 | 23 |
24 Future run() async { | 24 Future run() async { |
25 var successes = 0; | 25 var successes = []; |
26 var failures = 0; | 26 var failures = []; |
27 | 27 |
28 // Repair every cached source. | 28 // Repair every cached source. |
29 for (var source in cache.sources) { | 29 for (var source in cache.sources) { |
30 if (source is! CachedSource) continue; | 30 if (source is! CachedSource) continue; |
31 | 31 |
32 var results = await source.repairCachedPackages(); | 32 var results = await source.repairCachedPackages(); |
33 successes += results.first; | 33 successes.addAll(results.first); |
34 failures += results.last; | 34 failures.addAll(results.last); |
35 } | 35 } |
36 | 36 |
37 if (successes > 0) { | 37 if (successes.length > 0) { |
38 var packages = pluralize("package", successes); | 38 var packages = pluralize("package", successes.length); |
39 log.message("Reinstalled ${log.green(successes)} $packages."); | 39 log.message("Reinstalled ${log.green(successes.length)} $packages."); |
40 } | 40 } |
41 | 41 |
42 if (failures > 0) { | 42 if (failures.length > 0) { |
43 var packages = pluralize("package", failures); | 43 var packages = pluralize("package", failures.length); |
44 log.message("Failed to reinstall ${log.red(failures)} $packages."); | 44 var buffer = new StringBuffer( |
| 45 "Failed to reinstall ${log.red(failures.length)} $packages:\n"); |
| 46 |
| 47 for (var id in failures) { |
| 48 buffer.write("- ${log.bold(id.name)} ${id.version}"); |
| 49 if (cache.sources[id.source] != cache.sources.defaultSource) { |
| 50 buffer.write(" from ${id.source}"); |
| 51 } |
| 52 buffer.writeln(); |
| 53 } |
| 54 |
| 55 log.message(buffer.toString()); |
45 } | 56 } |
46 | 57 |
47 var results = await globals.repairActivatedPackages(); | 58 var results = await globals.repairActivatedPackages(); |
48 if (results.first > 0) { | 59 if (results.first.length > 0) { |
49 var packages = pluralize("package", results.first); | 60 var packages = pluralize("package", results.first.length); |
50 log.message("Reactivated ${log.green(results.first)} $packages."); | 61 log.message("Reactivated ${log.green(results.first.length)} $packages."); |
51 } | 62 } |
52 | 63 |
53 if (results.last > 0) { | 64 if (results.last.length > 0) { |
54 var packages = pluralize("package", results.last); | 65 var packages = pluralize("package", results.last.length); |
55 log.message("Failed to reactivate ${log.red(results.last)} $packages."); | 66 log.message( |
| 67 "Failed to reactivate ${log.red(results.last.length)} $packages:\n" + |
| 68 results.last.map((name) => "- ${log.bold(name)}").join("\n")); |
56 } | 69 } |
57 | 70 |
58 if (successes == 0 && failures == 0) { | 71 if (successes.length == 0 && failures.length == 0) { |
59 log.message("No packages in cache, so nothing to repair."); | 72 log.message("No packages in cache, so nothing to repair."); |
60 } | 73 } |
61 | 74 |
62 if (failures > 0) await flushThenExit(exit_codes.UNAVAILABLE); | 75 if (failures.length > 0 || results.last.length > 0) { |
| 76 await flushThenExit(exit_codes.UNAVAILABLE); |
| 77 } |
63 } | 78 } |
64 } | 79 } |
OLD | NEW |