2021-02-25 15:44:44 +05:30
|
|
|
extern crate clap;
|
|
|
|
|
|
|
|
use clap::{App, Arg};
|
|
|
|
use std::path::Path;
|
2021-09-06 21:31:37 +05:30
|
|
|
use std::process;
|
2021-10-11 16:37:26 +05:30
|
|
|
|
|
|
|
use crate::cache::dump::{dump, CacheDumpOptions};
|
|
|
|
use crate::commands::utils::*;
|
2021-02-25 15:44:44 +05:30
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
2021-10-11 16:37:26 +05:30
|
|
|
pub fn run(args: &[std::ffi::OsString]) {
|
2021-03-30 21:13:40 +05:30
|
|
|
let parser = App::new("cache_dump")
|
2021-10-11 16:37:26 +05:30
|
|
|
.version(crate::version::tools_version())
|
2021-06-15 14:07:04 +05:30
|
|
|
.about("Dump the cache metadata to stdout in XML format")
|
2021-06-23 10:14:38 +05:30
|
|
|
// flags
|
2021-06-23 09:10:12 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("ASYNC_IO")
|
|
|
|
.help("Force use of io_uring for synchronous io")
|
|
|
|
.long("async-io")
|
|
|
|
.hidden(true),
|
|
|
|
)
|
2021-06-15 14:07:04 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("REPAIR")
|
|
|
|
.help("Repair the metadata whilst dumping it")
|
|
|
|
.short("r")
|
|
|
|
.long("repair"),
|
|
|
|
)
|
2021-06-23 10:14:38 +05:30
|
|
|
// options
|
2021-06-15 14:07:04 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("OUTPUT")
|
|
|
|
.help("Specify the output file rather than stdout")
|
|
|
|
.short("o")
|
|
|
|
.long("output")
|
2021-08-23 23:47:24 +05:30
|
|
|
.value_name("FILE"),
|
2021-06-15 14:07:04 +05:30
|
|
|
)
|
2021-06-23 10:14:38 +05:30
|
|
|
// arguments
|
2021-02-25 15:44:44 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("INPUT")
|
2021-06-15 14:07:04 +05:30
|
|
|
.help("Specify the input device to dump")
|
2021-02-25 15:44:44 +05:30
|
|
|
.required(true)
|
|
|
|
.index(1),
|
|
|
|
);
|
|
|
|
|
2021-10-11 16:37:26 +05:30
|
|
|
let matches = parser.get_matches_from(args);
|
2021-02-25 15:44:44 +05:30
|
|
|
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
2021-06-15 14:07:04 +05:30
|
|
|
let output_file = if matches.is_present("OUTPUT") {
|
|
|
|
Some(Path::new(matches.value_of("OUTPUT").unwrap()))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2021-02-25 15:44:44 +05:30
|
|
|
|
2021-10-11 16:37:26 +05:30
|
|
|
// Create a temporary report just in case these checks
|
|
|
|
// need to report anything.
|
|
|
|
let report = std::sync::Arc::new(crate::report::mk_simple_report());
|
|
|
|
check_input_file(input_file, &report);
|
|
|
|
check_file_not_tiny(input_file, &report);
|
|
|
|
drop(report);
|
2021-09-06 21:31:37 +05:30
|
|
|
|
2021-02-25 15:44:44 +05:30
|
|
|
let opts = CacheDumpOptions {
|
2021-06-15 14:07:04 +05:30
|
|
|
input: input_file,
|
|
|
|
output: output_file,
|
2021-06-23 09:10:12 +05:30
|
|
|
async_io: matches.is_present("ASYNC_IO"),
|
2021-02-25 15:44:44 +05:30
|
|
|
repair: matches.is_present("REPAIR"),
|
|
|
|
};
|
|
|
|
|
|
|
|
if let Err(reason) = dump(opts) {
|
|
|
|
eprintln!("{}", reason);
|
2021-09-06 21:31:37 +05:30
|
|
|
process::exit(1);
|
2021-02-25 15:44:44 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|