[thin_check (rust)] move report creation to top level

This commit is contained in:
Joe Thornber 2020-08-17 15:52:12 +01:00
parent 5743e3e9ba
commit e8d7e5cf1e
4 changed files with 19 additions and 5 deletions

1
Cargo.lock generated
View File

@ -704,6 +704,7 @@ name = "thinp"
version = "0.1.0"
dependencies = [
"anyhow",
"atty",
"base64",
"byteorder",
"clap",

View File

@ -6,6 +6,7 @@ edition = "2018"
license = "GPL3"
[dependencies]
atty = "0.2"
anyhow = "1.0"
base64 = "0.12"
byteorder = "1.3"

View File

@ -1,13 +1,15 @@
extern crate clap;
extern crate thinp;
use atty::Stream;
use clap::{App, Arg};
use std::path::Path;
use std::process;
use thinp::file_utils;
use thinp::thin::check::{check, ThinCheckOptions};
use std::sync::Arc;
use std::process::exit;
use thinp::report::*;
fn main() {
let parser = App::new("thin_check")
@ -18,7 +20,6 @@ fn main() {
.help("Suppress output messages, return only exit code.")
.short("q")
.long("quiet")
.value_name("QUIET"),
)
.arg(
Arg::with_name("SB_ONLY")
@ -74,9 +75,20 @@ fn main() {
exit(1);
}
let report;
if matches.is_present("QUIET") {
report = std::sync::Arc::new(mk_quiet_report());
} else if atty::is(Stream::Stdout) {
report = std::sync::Arc::new(mk_progress_bar_report());
} else {
report = Arc::new(mk_simple_report());
}
let opts = ThinCheckOptions {
dev: &input_file,
async_io: !matches.is_present("SYNC_IO"),
report
};
if let Err(reason) = check(&opts) {

View File

@ -257,9 +257,11 @@ const MAX_CONCURRENT_IO: u32 = 1024;
pub struct ThinCheckOptions<'a> {
pub dev: &'a Path,
pub async_io: bool,
pub report: Arc<Report>,
}
pub fn check(opts: &ThinCheckOptions) -> Result<()> {
let report = opts.report.clone();
let engine: Arc<dyn IoEngine + Send + Sync>;
let nr_threads;
@ -286,9 +288,7 @@ pub fn check(opts: &ThinCheckOptions) -> Result<()> {
let devs = btree_to_map::<DeviceDetail>(engine.clone(), false, sb.details_root)?;
let nr_devs = devs.len();
let metadata_sm = core_sm(engine.get_nr_blocks(), nr_devs as u32);
let report = Arc::new(mk_progress_bar_report());
//let report = Arc::new(mk_simple_report());
//let report = Arc::new(mk_quiet_report());
report.set_title("Checking thin metadata");
let tid;