diff --git a/src/main.rs b/src/main.rs index d74c4fb4..de2f5d39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::{ collections::BTreeSet, ffi::OsString, mem::take, - path::PathBuf, + path::{Path, PathBuf}, process::{ExitCode, Termination}, sync::Arc, time::{Duration, Instant}, @@ -317,36 +317,7 @@ async fn entry() -> Result<()> { let tasks: Vec<_> = resolutions .into_iter() - .map(|resolution| match resolution { - Resolution::Fetch { - fetcher, - package, - crate_name, - version, - bin_path, - bin_files, - } => tokio::spawn(install_from_package( - fetcher, - opts.clone(), - package, - crate_name, - temp_dir.path().to_path_buf(), - version, - bin_path, - bin_files, - )), - Resolution::InstallFromSource { package } => { - if !opts.dry_run { - tokio::spawn(install_from_source(package, Arc::clone(&target))) - } else { - info!( - "Dry-run: running `cargo install {} --version {} --target {target}`", - package.name, package.version - ); - tokio::spawn(async { Ok(()) }) - } - } - }) + .map(|resolution| install(resolution, &opts, temp_dir.path(), &target)) .collect(); for task in tasks { @@ -528,6 +499,44 @@ fn collect_bin_files( Ok(bin_files) } +fn install( + resolution: Resolution, + opts: &Arc, + temp_dir: &Path, + target: &Arc, +) -> tokio::task::JoinHandle> { + match resolution { + Resolution::Fetch { + fetcher, + package, + crate_name, + version, + bin_path, + bin_files, + } => tokio::spawn(install_from_package( + fetcher, + opts.clone(), + package, + crate_name, + temp_dir.to_path_buf(), + version, + bin_path, + bin_files, + )), + Resolution::InstallFromSource { package } => { + if !opts.dry_run { + tokio::spawn(install_from_source(package, Arc::clone(target))) + } else { + info!( + "Dry-run: running `cargo install {} --version {} --target {target}`", + package.name, package.version + ); + tokio::spawn(async { Ok(()) }) + } + } + } +} + #[allow(unused, clippy::too_many_arguments)] async fn install_from_package( fetcher: Arc,