mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 14:28:42 +00:00
Add --maximum-resolution-timeout
(#1862)
* Add --maximum-resolution-timeout Fixed #1823 * Display default value for `--maximum-resolution-timeout` in help
This commit is contained in:
parent
de55e465f5
commit
52f2db4f57
5 changed files with 76 additions and 48 deletions
|
@ -40,6 +40,7 @@ tokio = { version = "1.35.0", features = [
|
|||
"rt",
|
||||
"process",
|
||||
"sync",
|
||||
"time",
|
||||
], default-features = false }
|
||||
tracing = "0.1.39"
|
||||
url = { version = "2.3.1", features = ["serde"] }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Concrete Binstall operations.
|
||||
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use std::{path::PathBuf, sync::Arc, time::Duration};
|
||||
|
||||
use semver::VersionReq;
|
||||
|
||||
|
@ -56,4 +56,6 @@ pub struct Options {
|
|||
|
||||
pub signature_policy: SignaturePolicy,
|
||||
pub disable_telemetry: bool,
|
||||
|
||||
pub maximum_resolution_timeout: Duration,
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use itertools::Itertools;
|
|||
use leon::Template;
|
||||
use maybe_owned::MaybeOwned;
|
||||
use semver::{Version, VersionReq};
|
||||
use tokio::task::spawn_blocking;
|
||||
use tokio::{task::spawn_blocking, time::timeout};
|
||||
use tracing::{debug, error, info, instrument, warn};
|
||||
use url::Url;
|
||||
|
||||
|
@ -182,62 +182,73 @@ async fn resolve_inner(
|
|||
}
|
||||
|
||||
for fetcher in handles {
|
||||
match AutoAbortJoinHandle::new(fetcher.clone().find())
|
||||
.flattened_join()
|
||||
.await
|
||||
match timeout(
|
||||
opts.maximum_resolution_timeout,
|
||||
AutoAbortJoinHandle::new(fetcher.clone().find()).flattened_join(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(true) => {
|
||||
// Generate temporary binary path
|
||||
let bin_path = opts.temp_dir.join(format!(
|
||||
"bin-{}-{}-{}",
|
||||
package_info.name,
|
||||
fetcher.target(),
|
||||
fetcher.fetcher_name()
|
||||
));
|
||||
Ok(ret) => match ret {
|
||||
Ok(true) => {
|
||||
// Generate temporary binary path
|
||||
let bin_path = opts.temp_dir.join(format!(
|
||||
"bin-{}-{}-{}",
|
||||
package_info.name,
|
||||
fetcher.target(),
|
||||
fetcher.fetcher_name()
|
||||
));
|
||||
|
||||
match download_extract_and_verify(
|
||||
fetcher.as_ref(),
|
||||
&bin_path,
|
||||
&package_info,
|
||||
&opts.install_path,
|
||||
opts.no_symlinks,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(bin_files) => {
|
||||
if !bin_files.is_empty() {
|
||||
return Ok(Resolution::Fetch(Box::new(ResolutionFetch {
|
||||
fetcher,
|
||||
new_version: package_info.version,
|
||||
name: package_info.name,
|
||||
version_req: version_req_str,
|
||||
source: package_info.source,
|
||||
bin_files,
|
||||
})));
|
||||
} else {
|
||||
warn!(
|
||||
"Error when checking binaries provided by fetcher {}: \
|
||||
match download_extract_and_verify(
|
||||
fetcher.as_ref(),
|
||||
&bin_path,
|
||||
&package_info,
|
||||
&opts.install_path,
|
||||
opts.no_symlinks,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(bin_files) => {
|
||||
if !bin_files.is_empty() {
|
||||
return Ok(Resolution::Fetch(Box::new(ResolutionFetch {
|
||||
fetcher,
|
||||
new_version: package_info.version,
|
||||
name: package_info.name,
|
||||
version_req: version_req_str,
|
||||
source: package_info.source,
|
||||
bin_files,
|
||||
})));
|
||||
} else {
|
||||
warn!(
|
||||
"Error when checking binaries provided by fetcher {}: \
|
||||
The fetcher does not provide any optional binary",
|
||||
fetcher.source_name(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
if let BinstallError::UserAbort = err {
|
||||
return Err(err);
|
||||
}
|
||||
warn!(
|
||||
"Error while downloading and extracting from fetcher {}: {}",
|
||||
fetcher.source_name(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
if let BinstallError::UserAbort = err {
|
||||
return Err(err);
|
||||
}
|
||||
warn!(
|
||||
"Error while downloading and extracting from fetcher {}: {}",
|
||||
fetcher.source_name(),
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(false) => (),
|
||||
Ok(false) => (),
|
||||
Err(err) => {
|
||||
warn!(
|
||||
"Error while checking fetcher {}: {}",
|
||||
fetcher.source_name(),
|
||||
err
|
||||
);
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
warn!(
|
||||
"Error while checking fetcher {}: {}",
|
||||
"Timeout reached while checking fetcher {}: {}",
|
||||
fetcher.source_name(),
|
||||
err
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue