diff --git a/src/drivers.rs b/src/drivers.rs index 9c36b051..b16513d9 100644 --- a/src/drivers.rs +++ b/src/drivers.rs @@ -110,7 +110,7 @@ pub async fn fetch_crate_cratesio( let main = src.join("main.rs"); let bin = src.join("bin"); - download_and_extract( + download_and_extract_with_filter( Url::parse(&crate_url)?, PkgFmt::Tgz, &temp_dir, diff --git a/src/fetchers/gh_crate_meta.rs b/src/fetchers/gh_crate_meta.rs index bc4575e6..82bdf3bc 100644 --- a/src/fetchers/gh_crate_meta.rs +++ b/src/fetchers/gh_crate_meta.rs @@ -43,7 +43,7 @@ impl super::Fetcher for GhCrateMeta { async fn fetch_and_extract(&self, dst: &Path) -> Result<(), BinstallError> { let url = self.url()?; info!("Downloading package from: '{url}'"); - download_and_extract:: bool, _>(url, self.pkg_fmt(), dst, None).await + download_and_extract(url, self.pkg_fmt(), dst).await } fn pkg_fmt(&self) -> PkgFmt { diff --git a/src/fetchers/quickinstall.rs b/src/fetchers/quickinstall.rs index 7d597d15..7d6ed14a 100644 --- a/src/fetchers/quickinstall.rs +++ b/src/fetchers/quickinstall.rs @@ -40,8 +40,7 @@ impl super::Fetcher for QuickInstall { async fn fetch_and_extract(&self, dst: &Path) -> Result<(), BinstallError> { let url = self.package_url(); info!("Downloading package from: '{url}'"); - download_and_extract:: bool, _>(Url::parse(&url)?, self.pkg_fmt(), dst, None) - .await + download_and_extract(Url::parse(&url)?, self.pkg_fmt(), dst).await } fn pkg_fmt(&self) -> PkgFmt { diff --git a/src/helpers.rs b/src/helpers.rs index d81bb775..679328cd 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -43,13 +43,26 @@ pub async fn remote_exists(url: Url, method: Method) -> Result>( + url: Url, + fmt: PkgFmt, + path: P, +) -> Result<(), BinstallError> { + download_and_extract_with_filter:: bool, _>(url, fmt, path.as_ref(), None).await +} + +/// Download a file from the provided URL and extract part of it to +/// the provided path. /// /// * `filter` - If Some, then it will pass the path of the file to it /// and only extract ones which filter returns `true`. /// Note that this is a best-effort and it only works when `fmt` /// is not `PkgFmt::Bin` or `PkgFmt::Zip`. -pub async fn download_and_extract bool + Send + 'static, P: AsRef>( +pub async fn download_and_extract_with_filter< + Filter: FnMut(&Path) -> bool + Send + 'static, + P: AsRef, +>( url: Url, fmt: PkgFmt, path: P,