mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-15 07:06:36 +00:00
Modify helpers::download
to accept Url
for url
In `GhCrateMeta::fetch`, it parses `&str` to `Url` and then back to `&str`, then `helpers::download` parses it yet again to `Url`. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
43d5a6bdb1
commit
d8624f9018
4 changed files with 5 additions and 5 deletions
|
@ -5,6 +5,7 @@ use std::time::Duration;
|
|||
use crates_io_api::AsyncClient;
|
||||
use log::debug;
|
||||
use semver::{Version, VersionReq};
|
||||
use url::Url;
|
||||
|
||||
use crate::{helpers::*, BinstallError, PkgFmt};
|
||||
|
||||
|
@ -103,7 +104,7 @@ pub async fn fetch_crate_cratesio(
|
|||
debug!("Fetching crate from: {crate_url}");
|
||||
|
||||
// Download crate
|
||||
download(&crate_url, &tgz_path).await?;
|
||||
download(Url::parse(&crate_url)?, &tgz_path).await?;
|
||||
|
||||
// Decompress downloaded tgz
|
||||
debug!("Decompressing crate archive");
|
||||
|
|
|
@ -43,7 +43,7 @@ impl super::Fetcher for GhCrateMeta {
|
|||
async fn fetch(&self, dst: &Path) -> Result<(), BinstallError> {
|
||||
let url = self.url()?;
|
||||
info!("Downloading package from: '{url}'");
|
||||
download(url.as_str(), dst).await
|
||||
download(url, dst).await
|
||||
}
|
||||
|
||||
fn pkg_fmt(&self) -> PkgFmt {
|
||||
|
|
|
@ -39,7 +39,7 @@ impl super::Fetcher for QuickInstall {
|
|||
async fn fetch(&self, dst: &Path) -> Result<(), BinstallError> {
|
||||
let url = self.package_url();
|
||||
info!("Downloading package from: '{url}'");
|
||||
download(&url, &dst).await
|
||||
download(Url::parse(&url)?, &dst).await
|
||||
}
|
||||
|
||||
fn pkg_fmt(&self) -> PkgFmt {
|
||||
|
|
|
@ -41,8 +41,7 @@ pub async fn remote_exists(url: Url, method: Method) -> Result<bool, BinstallErr
|
|||
}
|
||||
|
||||
/// Download a file from the provided URL to the provided path
|
||||
pub async fn download<P: AsRef<Path>>(url: &str, path: P) -> Result<(), BinstallError> {
|
||||
let url = Url::parse(url)?;
|
||||
pub async fn download<P: AsRef<Path>>(url: Url, path: P) -> Result<(), BinstallError> {
|
||||
debug!("Downloading from: '{url}'");
|
||||
|
||||
let resp = reqwest::get(url.clone())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue