diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-12-09 13:31:32 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-12-09 14:52:09 +0100 |
commit | 087cecf01ebdbe12902faa8edb8247c16342a996 (patch) | |
tree | f5127c29f204cf931a68dc66b8bf542cae664412 /src/commands | |
parent | 4899ec32f152b8b598d67360e68e9054bfa1bdf6 (diff) |
Add progress spinners for source verification routines.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/build.rs | 2 | ||||
-rw-r--r-- | src/commands/source.rs | 29 |
2 files changed, 21 insertions, 10 deletions
diff --git a/src/commands/build.rs b/src/commands/build.rs index c0c2f59..7d7f96a 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -179,7 +179,7 @@ pub async fn build(matches: &ArgMatches, if matches.is_present("no_verification") { warn!("No hash verification will be performed"); } else { - crate::commands::source::verify_impl(tree.all_packages().into_iter(), &source_cache) + crate::commands::source::verify_impl(tree.all_packages().into_iter(), &source_cache, &progressbars) .await?; } diff --git a/src/commands/source.rs b/src/commands/source.rs index c14d123..c4ad11a 100644 --- a/src/commands/source.rs +++ b/src/commands/source.rs @@ -1,12 +1,13 @@ use std::io::Write; use std::path::PathBuf; +use std::sync::Arc; use anyhow::anyhow; use anyhow::Error; use anyhow::Context; use anyhow::Result; use clap::ArgMatches; -use log::trace; +use log::{info, trace}; use tokio::stream::StreamExt; use tokio::io::AsyncWriteExt; @@ -20,7 +21,7 @@ use crate::util::progress::ProgressBars; pub async fn source(matches: &ArgMatches, config: &Configuration, repo: Repository, progressbars: ProgressBars) -> Result<()> { match matches.subcommand() { - Some(("verify", matches)) => verify(matches, config, repo).await, + Some(("verify", matches)) => verify(matches, config, repo, progressbars).await, Some(("list-missing", matches)) => list_missing(matches, config, repo).await, Some(("url", matches)) => url(matches, repo).await, Some(("download", matches)) => download(matches, config, repo, progressbars).await, @@ -29,7 +30,7 @@ pub async fn source(matches: &ArgMatches, config: &Configuration, repo: Reposito } } -pub async fn verify(matches: &ArgMatches, config: &Configuration, repo: Repository) -> Result<()> { +pub async fn verify(matches: &ArgMatches, config: &Configuration, repo: Repository, progressbars: ProgressBars) -> Result<()> { let sc = SourceCache::new(config.source_cache_root().clone()); let pname = matches.value_of("package_name").map(String::from).map(PackageName::from); let pvers = matches.value_of("package_version").map(String::from).map(PackageVersionConstraint::new).transpose()?; @@ -38,29 +39,39 @@ pub async fn verify(matches: &ArgMatches, config: &Configuration, repo: Reposito .filter(|p| pname.as_ref().map(|n| p.name() == n).unwrap_or(true)) .filter(|p| pvers.as_ref().map(|v| v.matches(p.version())).unwrap_or(true)); - verify_impl(packages, &sc).await + verify_impl(packages, &sc, &progressbars).await } -pub (in crate::commands) async fn verify_impl<'a, I>(packages: I, sc: &SourceCache) -> Result<()> +pub (in crate::commands) async fn verify_impl<'a, I>(packages: I, sc: &SourceCache, progressbars: &ProgressBars) -> Result<()> where I: Iterator<Item = &'a Package> + 'a { + + let multi = Arc::new(indicatif::MultiProgress::new()); + let results = packages .map(|p| sc.sources_for(p).into_iter()) .flatten() - .map(|source| async move { + .map(|src| (multi.clone(), src)) + .map(|(multi, source)| async move { + let bar = multi.add(progressbars.verification_bar(source.path())); if source.path().exists() { source.verify_hash() .await .with_context(|| anyhow!("Hash verification failed for: {}", source.path().display()))?; - Ok(format!("Ok: {}", source.path().display())) + let msg = format!("Ok: {}", source.path().display()); + bar.finish_with_message(&msg); + Ok(msg) } else { + bar.finish_with_message("Error"); Err(anyhow!("Source missing: {}", source.path().display())) } }) .collect::<futures::stream::FuturesUnordered<_>>() - .collect::<Vec<Result<String>>>() - .await; + .collect::<Vec<Result<String>>>(); + + let (results, _) = tokio::join!(results, async move { multi.join() }); + info!("Verification processes finished"); let out = std::io::stdout(); let mut any_error = false; |