From 8cfc3fdb4f4c261f66d3d44825f5b61262bbac8d Mon Sep 17 00:00:00 2001 From: Abdulla Abdurakhmanov Date: Sun, 11 Aug 2024 19:44:05 +0200 Subject: [PATCH] Progress bar update to files counter instead of bytes --- src/args.rs | 2 +- src/commands/copy_command.rs | 16 +++++++++------- src/errors.rs | 3 +++ src/redacters/mod.rs | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/args.rs b/src/args.rs index f255ac0..61ee878 100644 --- a/src/args.rs +++ b/src/args.rs @@ -158,7 +158,7 @@ impl TryInto for RedacterArgs { fn try_into(self) -> Result { let mut provider_options = Vec::with_capacity(self.redact.as_ref().map(Vec::len).unwrap_or(0)); - for options in self.redact.unwrap_or_else(|| Vec::new()) { + for options in self.redact.unwrap_or_else(Vec::new) { let redacter_options = match options { RedacterType::GcpDlp => match self.gcp_project_id { Some(ref project_id) => { diff --git a/src/commands/copy_command.rs b/src/commands/copy_command.rs index 212255e..e8a64df 100644 --- a/src/commands/copy_command.rs +++ b/src/commands/copy_command.rs @@ -72,10 +72,12 @@ pub async fn command_copy( .as_str(), )?; let bar = ProgressBar::new(1); - bar.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})") - .unwrap() - .with_key("eta", |state: &ProgressState, w: &mut dyn Write| write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap()) - .progress_chars("◉>◯")); + bar.set_style( + ProgressStyle::with_template( + "{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {pos:>3}/{len:3}", + )? + .progress_chars("◉>◯"), + ); bar.enable_steady_tick(Duration::from_millis(100)); let app_reporter = AppReporter::from(&bar); @@ -117,7 +119,7 @@ pub async fn command_copy( .as_str(), ); - bar.set_length(files_total_size); + bar.set_length(files_found as u64); let mut total_files_copied = 0; let mut total_files_skipped = source_files_result.skipped; for source_file in source_files { @@ -190,7 +192,7 @@ async fn transfer_and_redact_file< let base_resolved_file_ref = source_fs.resolve(Some(&base_file_ref)); match options.file_matcher.matches(&base_file_ref) { FileMatcherResult::SkippedDueToSize | FileMatcherResult::SkippedDueToName => { - bar.inc(base_file_ref.file_size.unwrap_or(0)); + bar.inc(1); return Ok(TransferFileResult::Skipped); } FileMatcherResult::Matched => {} @@ -234,7 +236,7 @@ async fn transfer_and_redact_file< .await?; TransferFileResult::Copied }; - bar.inc(file_ref.file_size.unwrap_or(0)); + bar.inc(1); Ok(transfer_result) } diff --git a/src/errors.rs b/src/errors.rs index ee62e58..4ca5002 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,4 +1,5 @@ use gcloud_sdk::tonic::metadata::errors::InvalidMetadataValue; +use indicatif::style::TemplateError; use thiserror::Error; #[derive(Error, Debug)] @@ -31,6 +32,8 @@ pub enum AppError { CsvParserError(#[from] csv_async::Error), #[error("Redacter config error: {message}")] RedacterConfigError { message: String }, + #[error("Template error: {0}")] + TemplateError(#[from] TemplateError), #[error("System error: {message}")] SystemError { message: String }, } diff --git a/src/redacters/mod.rs b/src/redacters/mod.rs index b5eac7b..1286825 100644 --- a/src/redacters/mod.rs +++ b/src/redacters/mod.rs @@ -302,7 +302,7 @@ pub async fn redact_stream< bar.println(format!( "Redacting {} with {} redacter", file_ref.relative_path.value(), - redacter.redacter_type().to_string() + redacter.redacter_type() )); item_to_redact = redacter.redact(item_to_redact).await?; }