From e8d7e5cf1ecb02dbca8f71e1914d360b95218cb1 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 17 Aug 2020 15:52:12 +0100 Subject: [PATCH] [thin_check (rust)] move report creation to top level --- Cargo.lock | 1 + Cargo.toml | 1 + src/bin/thin_check.rs | 16 ++++++++++++++-- src/thin/check.rs | 6 +++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6d5c20..610c998 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -704,6 +704,7 @@ name = "thinp" version = "0.1.0" dependencies = [ "anyhow", + "atty", "base64", "byteorder", "clap", diff --git a/Cargo.toml b/Cargo.toml index 86626a8..d58ec14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2018" license = "GPL3" [dependencies] +atty = "0.2" anyhow = "1.0" base64 = "0.12" byteorder = "1.3" diff --git a/src/bin/thin_check.rs b/src/bin/thin_check.rs index 2c74c46..671d285 100644 --- a/src/bin/thin_check.rs +++ b/src/bin/thin_check.rs @@ -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) { diff --git a/src/thin/check.rs b/src/thin/check.rs index c69c5ce..b307108 100644 --- a/src/thin/check.rs +++ b/src/thin/check.rs @@ -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, } pub fn check(opts: &ThinCheckOptions) -> Result<()> { + let report = opts.report.clone(); let engine: Arc; let nr_threads; @@ -286,9 +288,7 @@ pub fn check(opts: &ThinCheckOptions) -> Result<()> { let devs = btree_to_map::(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;