Skip to content

Commit

Permalink
fix: in case of a version mismatch, fetch the correct version
Browse files Browse the repository at this point in the history
Closes: #673
  • Loading branch information
ctron committed Jan 26, 2024
1 parent f42e7c2 commit c997973
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,24 +259,29 @@ pub async fn get(
// consider system installed version

if let Some(required_version) = version {
// we have a version requirement
if required_version == detected_version {
tracing::info!(app = %app.name(), %detected_version, "using system installed binary");
// and a match, so return early
tracing::info!(app = %app.name(), %detected_version, "using system installed binary: {}", path.display());
return Ok(path);
} else if offline {
// a mismatch, in offline mode, we can't help here
bail!(
"couldn't find the required version ({required_version}) of the application {} (found: {detected_version})",
app.name(),
)
"couldn't find the required version ({required_version}) of the application {} (found: {detected_version}), unable to download in offline mode",
app.name(),
)
} else {
// a mismatch, so we need to download
tracing::info!(app = %app.name(), "tool version mismatch (required: {required_version}, system: {detected_version})");
}
}

return Ok(path);
}

if offline {
return Err(anyhow!("couldn't find application {}", &app.name()));
return Err(anyhow!(
"couldn't find application {}, unable to download in offline mode",
&app.name()
));
}

let cache_dir = cache_dir().await?;
Expand All @@ -292,10 +297,16 @@ pub async fn get(
.await?;
}

tracing::debug!(
"Using {} ({version}) from: {}",
app.name(),
bin_path.display()
);

Ok(bin_path)
}

/// Try to find a globally system installed version of the application.
/// Try to find a global system installed version of the application.
#[tracing::instrument(level = "trace")]
pub async fn find_system(app: Application) -> Option<(PathBuf, String)> {
let result = || async {
Expand Down

0 comments on commit c997973

Please sign in to comment.