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:
Jiahao XU 2022-06-08 19:17:12 +10:00
parent 43d5a6bdb1
commit d8624f9018
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
4 changed files with 5 additions and 5 deletions

View file

@ -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");

View file

@ -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 {

View file

@ -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 {

View file

@ -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())