OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library pub.command.cache_repair; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import '../command.dart'; | |
10 import '../exit_codes.dart' as exit_codes; | |
11 import '../io.dart'; | |
12 import '../log.dart' as log; | |
13 import '../source/cached.dart'; | |
14 import '../utils.dart'; | |
15 | |
16 /// Handles the `cache repair` pub command. | |
17 class CacheRepairCommand extends PubCommand { | |
18 String get name => "repair"; | |
19 String get description => "Reinstall cached packages."; | |
20 String get invocation => "pub cache repair"; | |
21 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-cache.html"; | |
22 bool get takesArguments => false; | |
23 | |
24 Future run() async { | |
25 var successes = 0; | |
26 var failures = 0; | |
27 | |
28 // Repair every cached source. | |
29 for (var source in cache.sources) { | |
30 if (source is! CachedSource) continue; | |
31 | |
32 var results = await source.repairCachedPackages(); | |
33 successes += results.first; | |
34 failures += results.last; | |
35 } | |
36 | |
37 if (successes > 0) { | |
38 var packages = pluralize("package", successes); | |
39 log.message("Reinstalled ${log.green(successes)} $packages."); | |
40 } | |
41 | |
42 if (failures > 0) { | |
43 var packages = pluralize("package", failures); | |
44 log.message("Failed to reinstall ${log.red(failures)} $packages."); | |
45 } | |
46 | |
47 var results = await globals.repairActivatedPackages(); | |
48 if (results.first > 0) { | |
49 var packages = pluralize("package", results.first); | |
50 log.message("Reactivated ${log.green(results.first)} $packages."); | |
51 } | |
52 | |
53 if (results.last > 0) { | |
54 var packages = pluralize("package", results.last); | |
55 log.message("Failed to reactivate ${log.red(results.last)} $packages."); | |
56 } | |
57 | |
58 if (successes == 0 && failures == 0) { | |
59 log.message("No packages in cache, so nothing to repair."); | |
60 } | |
61 | |
62 if (failures > 0) await flushThenExit(exit_codes.UNAVAILABLE); | |
63 } | |
64 } | |
OLD | NEW |