Skip to content

Commit

Permalink
Fix a bug where we would create a progress bar for each argument pass…
Browse files Browse the repository at this point in the history
…ed into rrm
  • Loading branch information
wykurz committed Dec 1, 2023
1 parent eec8b75 commit 9f6000b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
22 changes: 3 additions & 19 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,48 +75,31 @@ impl Drop for ProgressTracker {
}

pub async fn copy(
show_progress: bool,
src: &std::path::Path,
dst: &std::path::Path,
settings: &copy::Settings,
) -> Result<()> {
let _progress = match show_progress {
true => Some(ProgressTracker::new("copy")),
false => None,
};
copy::copy(&PROGRESS, src, dst, settings).await?;
Ok(())
}

pub async fn rm(
show_progress: bool,
path: &std::path::Path,
settings: &rm::Settings,
) -> Result<()> {
let _progress = match show_progress {
true => Some(ProgressTracker::new("remove")),
false => None,
};
pub async fn rm(path: &std::path::Path, settings: &rm::Settings) -> Result<()> {
rm::rm(&PROGRESS, path, settings).await?;
Ok(())
}

pub async fn link(
show_progress: bool,
src: &std::path::Path,
dst: &std::path::Path,
update: &Option<std::path::PathBuf>,
settings: &copy::Settings,
) -> Result<()> {
let _progress = match show_progress {
true => Some(ProgressTracker::new("copy")),
false => None,
};
copy::link(&PROGRESS, src, dst, update, settings).await?;
Ok(())
}

pub fn run<Fut>(
progress_op_name: Option<&str>,
quiet: bool,
verbose: u8,
max_workers: usize,
Expand All @@ -126,6 +109,7 @@ pub fn run<Fut>(
where
Fut: Future<Output = Result<()>>,
{
let _progress = progress_op_name.map(ProgressTracker::new);
if !quiet {
env_logger::Builder::new()
.target(env_logger::Target::Stdout)
Expand Down
2 changes: 1 addition & 1 deletion rcp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ async fn async_main(args: Args) -> Result<()> {
}
}
common::copy(
args.progress,
&src_path,
&dst_path,
&common::CopySettings {
Expand Down Expand Up @@ -144,6 +143,7 @@ fn main() -> Result<()> {
|| async_main(args)
};
common::run(
if args.progress { Some("copy") } else { None },
args.quiet,
args.verbose,
args.max_workers,
Expand Down
2 changes: 1 addition & 1 deletion rlink/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ async fn async_main(args: Args) -> Result<()> {
.unwrap()
.as_u64() as usize;
common::link(
args.progress,
&args.src,
&args.dst,
&args.update,
Expand All @@ -99,6 +98,7 @@ fn main() -> Result<()> {
|| async_main(args)
};
common::run(
if args.progress { Some("rlink") } else { None },
args.quiet,
args.verbose,
args.max_workers,
Expand Down
3 changes: 2 additions & 1 deletion rrm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async fn async_main(args: Args) -> Result<()> {
let settings = common::RmSettings {
fail_early: args.fail_early,
};
let do_rm = || async move { common::rm(args.progress, &path, &settings).await };
let do_rm = || async move { common::rm(&path, &settings).await };
join_set.spawn(do_rm());
}
let mut success = true;
Expand All @@ -65,6 +65,7 @@ fn main() -> Result<()> {
|| async_main(args)
};
common::run(
if args.progress { Some("rm") } else { None },
args.quiet,
args.verbose,
args.max_workers,
Expand Down

0 comments on commit 9f6000b

Please sign in to comment.