mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Simplify download_and_extract_with_filter
: Take TarBasedFmt
instead of `PkgFmt` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
cbd57a1bce
commit
b1b79921b2
2 changed files with 5 additions and 11 deletions
|
@ -7,7 +7,7 @@ use log::debug;
|
||||||
use semver::{Version, VersionReq};
|
use semver::{Version, VersionReq};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{helpers::*, BinstallError, PkgFmt};
|
use crate::{helpers::*, BinstallError, TarBasedFmt};
|
||||||
|
|
||||||
fn find_version<'a, V: Iterator<Item = &'a String>>(
|
fn find_version<'a, V: Iterator<Item = &'a String>>(
|
||||||
requirement: &str,
|
requirement: &str,
|
||||||
|
@ -112,7 +112,7 @@ pub async fn fetch_crate_cratesio(
|
||||||
|
|
||||||
download_and_extract_with_filter(
|
download_and_extract_with_filter(
|
||||||
Url::parse(&crate_url)?,
|
Url::parse(&crate_url)?,
|
||||||
PkgFmt::Tgz,
|
TarBasedFmt::Tgz,
|
||||||
&temp_dir,
|
&temp_dir,
|
||||||
Some(move |path: &Path| path == cargo_toml || path == main || path.starts_with(&bin)),
|
Some(move |path: &Path| path == cargo_toml || path == main || path.starts_with(&bin)),
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,7 +7,7 @@ use serde::Serialize;
|
||||||
use tinytemplate::TinyTemplate;
|
use tinytemplate::TinyTemplate;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{BinstallError, Meta, PkgFmt, PkgFmtDecomposed};
|
use crate::{BinstallError, Meta, PkgFmt, PkgFmtDecomposed, TarBasedFmt};
|
||||||
|
|
||||||
mod async_extracter;
|
mod async_extracter;
|
||||||
pub use async_extracter::*;
|
pub use async_extracter::*;
|
||||||
|
@ -92,7 +92,7 @@ pub async fn download_and_extract_with_filter<
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
>(
|
>(
|
||||||
url: Url,
|
url: Url,
|
||||||
fmt: PkgFmt,
|
fmt: TarBasedFmt,
|
||||||
path: P,
|
path: P,
|
||||||
filter: Option<Filter>,
|
filter: Option<Filter>,
|
||||||
) -> Result<(), BinstallError> {
|
) -> Result<(), BinstallError> {
|
||||||
|
@ -105,13 +105,7 @@ pub async fn download_and_extract_with_filter<
|
||||||
|
|
||||||
let stream = resp.bytes_stream();
|
let stream = resp.bytes_stream();
|
||||||
|
|
||||||
match fmt.decompose() {
|
extract_tar_based_stream_with_filter(stream, path, fmt, filter).await?;
|
||||||
PkgFmtDecomposed::Tar(fmt) => {
|
|
||||||
extract_tar_based_stream_with_filter(stream, path, fmt, filter).await?
|
|
||||||
}
|
|
||||||
PkgFmtDecomposed::Bin => extract_bin(stream, path).await?,
|
|
||||||
PkgFmtDecomposed::Zip => extract_zip(stream, path).await?,
|
|
||||||
}
|
|
||||||
|
|
||||||
debug!("Download OK, written to file: '{}'", path.display());
|
debug!("Download OK, written to file: '{}'", path.display());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue