diff --git a/src/binstall/resolve.rs b/src/binstall/resolve.rs index 91ad1f57..31b885bd 100644 --- a/src/binstall/resolve.rs +++ b/src/binstall/resolve.rs @@ -72,6 +72,7 @@ impl Resolution { } } +#[allow(clippy::too_many_arguments)] pub async fn resolve( opts: Arc, crate_name: CrateName, @@ -80,6 +81,7 @@ pub async fn resolve( temp_dir: Arc, install_path: Arc, client: Client, + crates_io_api_client: crates_io_api::AsyncClient, ) -> Result { info!("Installing package: '{}'", crate_name); @@ -105,7 +107,9 @@ pub async fn resolve( // TODO: support git-based fetches (whole repo name rather than just crate name) let manifest = match opts.manifest_path.clone() { Some(manifest_path) => load_manifest_path(manifest_path.join("Cargo.toml"))?, - None => fetch_crate_cratesio(&client, &crate_name.name, &version).await?, + None => { + fetch_crate_cratesio(&client, &crates_io_api_client, &crate_name.name, &version).await? + } }; let package = manifest.package.unwrap(); diff --git a/src/drivers/crates_io.rs b/src/drivers/crates_io.rs index a389f5d1..b7e96086 100644 --- a/src/drivers/crates_io.rs +++ b/src/drivers/crates_io.rs @@ -1,5 +1,4 @@ use std::path::PathBuf; -use std::time::Duration; use cargo_toml::Manifest; use crates_io_api::AsyncClient; @@ -18,28 +17,21 @@ use visitor::ManifestVisitor; /// Fetch a crate Cargo.toml by name and version from crates.io pub async fn fetch_crate_cratesio( client: &Client, + crates_io_api_client: &AsyncClient, name: &str, version_req: &str, ) -> Result, BinstallError> { // Fetch / update index debug!("Looking up crate information"); - // Build crates.io api client - let api_client = AsyncClient::new( - "cargo-binstall (https://github.com/ryankurte/cargo-binstall)", - Duration::from_millis(100), - ) - .expect("bug: invalid user agent"); - // Fetch online crate information - let base_info = - api_client - .get_crate(name.as_ref()) - .await - .map_err(|err| BinstallError::CratesIoApi { - crate_name: name.into(), - err, - })?; + let base_info = crates_io_api_client + .get_crate(name.as_ref()) + .await + .map_err(|err| BinstallError::CratesIoApi { + crate_name: name.into(), + err, + })?; // Locate matching version let version_iter = diff --git a/src/main.rs b/src/main.rs index a11e72f0..df166c41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -216,6 +216,13 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> { // Initialize reqwest client let client = create_reqwest_client(opts.secure, opts.min_tls_version.map(|v| v.into()))?; + // Build crates.io api client + let crates_io_api_client = crates_io_api::AsyncClient::new( + "cargo-binstall (https://github.com/ryankurte/cargo-binstall)", + Duration::from_millis(100), + ) + .expect("bug: invalid user agent"); + // Setup logging let mut log_config = ConfigBuilder::new(); log_config.add_filter_ignore("hyper".to_string()); @@ -273,6 +280,7 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> { temp_dir_path.clone(), install_path.clone(), client.clone(), + crates_io_api_client.clone(), )) }) .collect(); @@ -308,6 +316,7 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> { let jobserver_client = jobserver_client.clone(); let desired_targets = desired_targets.clone(); let client = client.clone(); + let crates_io_api_client = crates_io_api_client.clone(); let cli_overrides = cli_overrides.clone(); let install_path = install_path.clone(); @@ -320,6 +329,7 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> { temp_dir_path, install_path, client, + crates_io_api_client, ) .await?;