diff --git a/src/fetchers.rs b/src/fetchers.rs index e0b95063..a39a0e9a 100644 --- a/src/fetchers.rs +++ b/src/fetchers.rs @@ -17,8 +17,8 @@ pub trait Fetcher: Send + Sync { where Self: Sized; - /// Fetch a package - async fn fetch(&self, dst: &Path) -> Result<(), BinstallError>; + /// Fetch a package and extract + async fn fetch_and_extract(&self, dst: &Path) -> Result<(), BinstallError>; /// Check if a package is available for download async fn check(&self) -> Result; diff --git a/src/fetchers/gh_crate_meta.rs b/src/fetchers/gh_crate_meta.rs index e38d7ae1..c6ed669b 100644 --- a/src/fetchers/gh_crate_meta.rs +++ b/src/fetchers/gh_crate_meta.rs @@ -7,7 +7,7 @@ use serde::Serialize; use url::Url; use super::Data; -use crate::{download, remote_exists, BinstallError, PkgFmt, Template}; +use crate::{download_and_extract, remote_exists, BinstallError, PkgFmt, Template}; pub struct GhCrateMeta { data: Data, @@ -40,10 +40,10 @@ impl super::Fetcher for GhCrateMeta { remote_exists(url, Method::HEAD).await } - async fn fetch(&self, dst: &Path) -> Result<(), BinstallError> { + async fn fetch_and_extract(&self, dst: &Path) -> Result<(), BinstallError> { let url = self.url()?; info!("Downloading package from: '{url}'"); - download(url.as_str(), dst).await + download_and_extract::<_, 0>(url, self.pkg_fmt(), dst, None).await } fn pkg_fmt(&self) -> PkgFmt { diff --git a/src/fetchers/quickinstall.rs b/src/fetchers/quickinstall.rs index ec83493c..b934302e 100644 --- a/src/fetchers/quickinstall.rs +++ b/src/fetchers/quickinstall.rs @@ -6,7 +6,7 @@ use reqwest::Method; use url::Url; use super::Data; -use crate::{download, remote_exists, BinstallError, PkgFmt}; +use crate::{download_and_extract, remote_exists, BinstallError, PkgFmt}; const BASE_URL: &str = "https://github.com/alsuren/cargo-quickinstall/releases/download"; const STATS_URL: &str = "https://warehouse-clerk-tmp.vercel.app/api/crate"; @@ -36,10 +36,10 @@ impl super::Fetcher for QuickInstall { remote_exists(Url::parse(&url)?, Method::HEAD).await } - async fn fetch(&self, dst: &Path) -> Result<(), BinstallError> { + async fn fetch_and_extract(&self, dst: &Path) -> Result<(), BinstallError> { let url = self.package_url(); info!("Downloading package from: '{url}'"); - download(&url, &dst).await + download_and_extract::<_, 0>(Url::parse(&url)?, self.pkg_fmt(), dst, None).await } fn pkg_fmt(&self) -> PkgFmt { diff --git a/src/main.rs b/src/main.rs index 9b3dafb0..58460ebb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -361,11 +361,21 @@ async fn install_from_package( meta.bin_dir = "{ bin }{ binary-ext }".to_string(); } + let bin_path = temp_dir.path().join(format!("bin-{}", opts.name)); + debug!("Using temporary binary path: {}", bin_path.display()); + // Download package if opts.dry_run { info!("Dry run, not downloading package"); } else { - fetcher.fetch(&pkg_path).await?; + fetcher.fetch_and_extract(&bin_path).await?; + + if binaries.is_empty() { + error!("No binaries specified (or inferred from file system)"); + return Err(miette!( + "No binaries specified (or inferred from file system)" + )); + } } #[cfg(incomplete)] @@ -392,21 +402,6 @@ async fn install_from_package( } } - let bin_path = temp_dir.path().join(format!("bin-{}", opts.name)); - debug!("Using temporary binary path: {}", bin_path.display()); - - if !opts.dry_run { - // Extract files - extract(&pkg_path, fetcher.pkg_fmt(), &bin_path)?; - - if binaries.is_empty() { - error!("No binaries specified (or inferred from file system)"); - return Err(miette!( - "No binaries specified (or inferred from file system)" - )); - } - } - // List files to be installed // based on those found via Cargo.toml let bin_data = bins::Data {