blkar_lib/
cli_repair.rs

1use repair_core::Param;
2use repair_core;
3use std::str::FromStr;
4
5use clap::*;
6use cli_utils::*;
7
8use json_printer::BracketType;
9
10pub fn sub_command<'a, 'b>() -> App<'a, 'b> {
11    SubCommand::with_name("repair")
12        .about("Repair SBX container
13
14===== IMPORTANT =====
15Please note that this is the last version of this software to be released under the name rsbx,
16future releases will be published under the name blkar. See project repo for details.
17=====================")
18        .arg(in_file_arg()
19             .help("SBX container to repair"))
20        .arg(pr_verbosity_level_arg())
21        .arg(burst_arg()
22             .help("Burst error resistance level used by the container.
23Use this if the level used by the container is above 1000,
24as rsbx will only guess up to 1000. Or use this when rsbx
25fails to guess correctly."))
26        .arg(verbose_arg()
27             .help("Show reference block info, successes and failures of all required repairs"))
28        .arg(Arg::with_name("skip_warning")
29             .short("y")
30             .long("skip-warning")
31             .help("Skip warning about in-place automatic repairs"))
32        .arg(Arg::with_name("dry_run")
33             .long("dry-run")
34             .help("Only do repairs in memory. The container will not be modified."))
35        .arg(json_arg()
36             .help("Output information in JSON format. Note that rsbx does not
37guarantee the JSON data to be well-formed if rsbx is interrupted.
38This also implies --skip-warning, and changes progress report text
39(if any) to be in JSON."))
40}
41
42pub fn repair<'a>(matches : &ArgMatches<'a>) -> i32 {
43    let json_printer = get_json_printer!(matches);
44
45    json_printer.print_open_bracket(None, BracketType::Curly);
46
47    let in_file = get_in_file!(matches, json_printer);
48
49    let pr_verbosity_level = get_pr_verbosity_level!(matches, json_printer);
50
51    let burst = get_burst_opt!(matches, json_printer);
52
53    if matches.is_present("dry_run")
54        && !json_printer.json_enabled()
55    {
56        print_block!(
57            "Note : This is a dry run only, the container is not modified.";
58            "";
59        );
60    }
61
62    if !matches.is_present("skip_warning")
63        && !matches.is_present("dry_run")
64        && !json_printer.json_enabled()
65    {
66        print_block!(
67            "Warning :";
68            "";
69            "    Repair mode modifies the SBX container in-place.";
70            "";
71            "    This may cause further damage to the container and prohibit further";
72            "    data recovery if incorrect automatic repairs are made.";
73            "";
74            "    It is advisable to make a copy of the container and work on the copy";
75            "    rather than repairing the original container directly.";
76            "";
77        );
78
79        ask_if_wish_to_continue!();
80    }
81
82    let param = Param::new(in_file,
83                           matches.is_present("dry_run"),
84                           &json_printer,
85                           matches.is_present("verbose"),
86                           pr_verbosity_level,
87                           burst);
88    match repair_core::repair_file(&param) {
89        Ok(Some(s)) => exit_with_msg!(ok json_printer => "{}", s),
90        Ok(None)    => exit_with_msg!(ok json_printer => ""),
91        Err(e)      => exit_with_msg!(op json_printer => "{}", e),
92    }
93}