mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-16 15:46:36 +00:00
Parallelise <QuickInstall as Fetcher>::find
Check for signature in parallel to the package
This commit is contained in:
parent
2aeaa32c68
commit
9fbd62fe76
3 changed files with 67 additions and 16 deletions
|
@ -1,6 +1,11 @@
|
||||||
use std::sync::{
|
#![allow(unused)]
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
future::Future,
|
||||||
|
sync::{
|
||||||
atomic::{AtomicBool, Ordering::Relaxed},
|
atomic::{AtomicBool, Ordering::Relaxed},
|
||||||
Once,
|
Once,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(super) use binstalk_downloader::{
|
pub(super) use binstalk_downloader::{
|
||||||
|
@ -76,3 +81,33 @@ pub(super) async fn does_url_exist(
|
||||||
|
|
||||||
Ok(Box::pin(client.remote_gettable(url.clone())).await?)
|
Ok(Box::pin(client.remote_gettable(url.clone())).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(super) struct AutoAbortJoinHandle<T>(JoinHandle<T>);
|
||||||
|
|
||||||
|
impl<T> AutoAbortJoinHandle<T>
|
||||||
|
where
|
||||||
|
T: Send + 'static,
|
||||||
|
{
|
||||||
|
pub(super) fn spawn<F>(future: F) -> Self
|
||||||
|
where
|
||||||
|
F: Future<Output = T> + Send + 'static,
|
||||||
|
{
|
||||||
|
Self(tokio::spawn(future))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Drop for AutoAbortJoinHandle<T> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.0.abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, E> AutoAbortJoinHandle<Result<T, E>>
|
||||||
|
where
|
||||||
|
E: Into<FetchError>,
|
||||||
|
{
|
||||||
|
pub(super) async fn flattened_join(mut self) -> Result<T, FetchError> {
|
||||||
|
(&mut self.0).await?.map_err(Into::into)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use binstalk_downloader::{download::DownloadError, remote::Error as RemoteError}
|
||||||
use binstalk_git_repo_api::gh_api_client::{GhApiError, GhRepo};
|
use binstalk_git_repo_api::gh_api_client::{GhApiError, GhRepo};
|
||||||
use binstalk_types::cargo_toml_binstall::SigningAlgorithm;
|
use binstalk_types::cargo_toml_binstall::SigningAlgorithm;
|
||||||
use thiserror::Error as ThisError;
|
use thiserror::Error as ThisError;
|
||||||
use tokio::{sync::OnceCell, time::sleep};
|
use tokio::{sync::OnceCell, task::JoinError, time::sleep};
|
||||||
pub use url::ParseError as UrlParseError;
|
pub use url::ParseError as UrlParseError;
|
||||||
|
|
||||||
mod gh_crate_meta;
|
mod gh_crate_meta;
|
||||||
|
@ -70,6 +70,9 @@ pub enum FetchError {
|
||||||
|
|
||||||
#[error("Failed to verify signature")]
|
#[error("Failed to verify signature")]
|
||||||
InvalidSignature,
|
InvalidSignature,
|
||||||
|
|
||||||
|
#[error("Failed to wait for task: {0}")]
|
||||||
|
TaskJoinError(#[from] JoinError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<RemoteError> for FetchError {
|
impl From<RemoteError> for FetchError {
|
||||||
|
|
|
@ -118,22 +118,35 @@ impl super::Fetcher for QuickInstall {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.signature_policy == SignaturePolicy::Require {
|
let check_signature_policy_task = (self.signature_policy == SignaturePolicy::Require)
|
||||||
does_url_exist(
|
.then(|| {
|
||||||
self.client.clone(),
|
let client = self.client.clone();
|
||||||
self.gh_api_client.clone(),
|
let gh_api_client = self.gh_api_client.clone();
|
||||||
&self.signature_url,
|
let signature_url = self.signature_url.clone();
|
||||||
)
|
|
||||||
.await
|
|
||||||
.map_err(|_| FetchError::MissingSignature)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
AutoAbortJoinHandle::spawn(async move {
|
||||||
|
match does_url_exist(client, gh_api_client, &signature_url).await {
|
||||||
|
Ok(true) => Ok(()),
|
||||||
|
_ => Err(FetchError::MissingSignature),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::try_join!(
|
||||||
|
async {
|
||||||
|
if let Some(task) = check_signature_policy_task {
|
||||||
|
task.flattened_join().await
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
},
|
||||||
does_url_exist(
|
does_url_exist(
|
||||||
self.client.clone(),
|
self.client.clone(),
|
||||||
self.gh_api_client.clone(),
|
self.gh_api_client.clone(),
|
||||||
&self.package_url,
|
&self.package_url,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.await
|
.map(|(_, res)| res)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue