mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Fix fetcher::QuickInstall
stats report sending (#918)
Fixed https://github.com/cargo-bins/cargo-quickinstall/issues/195 - Fix `fetchers::QuickInstall`: Stop sending stats for `universal-apple-darwin` since quickinstall only supports targets officially supports by rust. - Only send stats report to quickinstall if the `Fetcher::find` is `.await`ed on This prevents stats report to be sent for cases where the `QuickInstall` fetcher is actually unused, e.g. resolved to `GhCrateMeta` or other `QuickInstall` fetcher with different target. This also reduces amount of http requests created in background. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
6843f478a9
commit
cc78ff3b90
3 changed files with 29 additions and 12 deletions
|
@ -44,6 +44,10 @@ pub trait Fetcher: Send + Sync {
|
||||||
/// fatal conditions only.
|
/// fatal conditions only.
|
||||||
fn find(self: Arc<Self>) -> AutoAbortJoinHandle<Result<bool, BinstallError>>;
|
fn find(self: Arc<Self>) -> AutoAbortJoinHandle<Result<bool, BinstallError>>;
|
||||||
|
|
||||||
|
/// Report to upstream that cargo-binstall tries to use this fetcher.
|
||||||
|
/// Currently it is only overriden by [`quickinstall::QuickInstall`].
|
||||||
|
fn report_to_upstream(self: Arc<Self>) {}
|
||||||
|
|
||||||
/// Return the package format
|
/// Return the package format
|
||||||
fn pkg_fmt(&self) -> PkgFmt;
|
fn pkg_fmt(&self) -> PkgFmt;
|
||||||
|
|
||||||
|
|
|
@ -63,18 +63,8 @@ impl super::Fetcher for QuickInstall {
|
||||||
|
|
||||||
fn find(self: Arc<Self>) -> AutoAbortJoinHandle<Result<bool, BinstallError>> {
|
fn find(self: Arc<Self>) -> AutoAbortJoinHandle<Result<bool, BinstallError>> {
|
||||||
AutoAbortJoinHandle::spawn(async move {
|
AutoAbortJoinHandle::spawn(async move {
|
||||||
if cfg!(debug_assertions) {
|
if self.target_data.target == "universal-apple-darwin" {
|
||||||
debug!("Not sending quickinstall report in debug mode");
|
return Ok(false);
|
||||||
} else {
|
|
||||||
let this = self.clone();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
if let Err(err) = this.report().await {
|
|
||||||
warn!(
|
|
||||||
"Failed to send quickinstall report for package {}: {err}",
|
|
||||||
this.package
|
|
||||||
)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
does_url_exist(
|
does_url_exist(
|
||||||
|
@ -86,6 +76,28 @@ impl super::Fetcher for QuickInstall {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn report_to_upstream(self: Arc<Self>) {
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
debug!("Not sending quickinstall report in debug mode");
|
||||||
|
} else if self.target_data.target == "universal-apple-darwin" {
|
||||||
|
debug!(
|
||||||
|
r#"Not sending quickinstall report for universal-apple-darwin
|
||||||
|
quickinstall does not support our homebrew target
|
||||||
|
universal-apple-darwin, it only supports targets supported by
|
||||||
|
rust officially."#,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
tokio::spawn(async move {
|
||||||
|
if let Err(err) = self.report().await {
|
||||||
|
warn!(
|
||||||
|
"Failed to send quickinstall report for package {}: {err}",
|
||||||
|
self.package
|
||||||
|
)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn fetch_and_extract(&self, dst: &Path) -> Result<ExtractedFiles, BinstallError> {
|
async fn fetch_and_extract(&self, dst: &Path) -> Result<ExtractedFiles, BinstallError> {
|
||||||
let url = &self.package_url;
|
let url = &self.package_url;
|
||||||
debug!("Downloading package from: '{url}'");
|
debug!("Downloading package from: '{url}'");
|
||||||
|
|
|
@ -118,6 +118,7 @@ async fn resolve_inner(
|
||||||
);
|
);
|
||||||
|
|
||||||
for (fetcher, handle) in handles {
|
for (fetcher, handle) in handles {
|
||||||
|
fetcher.clone().report_to_upstream();
|
||||||
match handle.flattened_join().await {
|
match handle.flattened_join().await {
|
||||||
Ok(true) => {
|
Ok(true) => {
|
||||||
// Generate temporary binary path
|
// Generate temporary binary path
|
||||||
|
|
Loading…
Add table
Reference in a new issue