Skip to content

Commit

Permalink
Progress bar update to files counter instead of bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Aug 11, 2024
1 parent 552813a commit 8cfc3fd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl TryInto<RedacterOptions> for RedacterArgs {
fn try_into(self) -> Result<RedacterOptions, Self::Error> {
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) => {
Expand Down
16 changes: 9 additions & 7 deletions src/commands/copy_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 => {}
Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 3 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use gcloud_sdk::tonic::metadata::errors::InvalidMetadataValue;
use indicatif::style::TemplateError;
use thiserror::Error;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -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 },
}
Expand Down
2 changes: 1 addition & 1 deletion src/redacters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
}
Expand Down

0 comments on commit 8cfc3fd

Please sign in to comment.