Skip to content

Commit

Permalink
Fix solana-install init making unnecessary API requests (solana-lab…
Browse files Browse the repository at this point in the history
…s#33949)

* Fix `solana-install init` making unnecessary API requests

* Add `is_init` check

* chore: Move `semver_update_type` to where it's being used
  • Loading branch information
acheroncrypto authored Nov 7, 2023
1 parent 8c69a0e commit ec0ddc9
Showing 1 changed file with 45 additions and 41 deletions.
86 changes: 45 additions & 41 deletions install/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,58 +968,62 @@ pub fn update(config_file: &str, check_only: bool) -> Result<bool, String> {
pub fn init_or_update(config_file: &str, is_init: bool, check_only: bool) -> Result<bool, String> {
let mut config = Config::load(config_file)?;

let semver_update_type = if is_init {
SemverUpdateType::Fixed
} else {
SemverUpdateType::Patch
};

let (updated_version, download_url_and_sha256, release_dir) = if let Some(explicit_release) =
&config.explicit_release
{
match explicit_release {
ExplicitRelease::Semver(current_release_semver) => {
let progress_bar = new_spinner_progress_bar();
progress_bar.set_message(format!("{LOOKING_GLASS}Checking for updates..."));

let github_release = check_for_newer_github_release(
current_release_semver,
semver_update_type,
is_init,
)?;

progress_bar.finish_and_clear();
let release_dir = config.release_dir(current_release_semver);
if is_init && release_dir.exists() {
(current_release_semver.to_owned(), None, release_dir)
} else {
let progress_bar = new_spinner_progress_bar();
progress_bar.set_message(format!("{LOOKING_GLASS}Checking for updates..."));

match github_release {
None => {
return Err(format!("Unknown release: {current_release_semver}"));
}
Some(release_semver) => {
if release_semver == *current_release_semver {
if let Ok(active_release_version) = load_release_version(
&config.active_release_dir().join("version.yml"),
) {
if format!("v{current_release_semver}")
== active_release_version.channel
{
println!(
let semver_update_type = if is_init {
SemverUpdateType::Fixed
} else {
SemverUpdateType::Patch
};
let github_release = check_for_newer_github_release(
current_release_semver,
semver_update_type,
is_init,
)?;

progress_bar.finish_and_clear();

match github_release {
None => {
return Err(format!("Unknown release: {current_release_semver}"));
}
Some(release_semver) => {
if release_semver == *current_release_semver {
if let Ok(active_release_version) = load_release_version(
&config.active_release_dir().join("version.yml"),
) {
if format!("v{current_release_semver}")
== active_release_version.channel
{
println!(
"Install is up to date. {release_semver} is the latest compatible release"
);
return Ok(false);
return Ok(false);
}
}
}
config.explicit_release =
Some(ExplicitRelease::Semver(release_semver.clone()));

let release_dir = config.release_dir(&release_semver);
let download_url_and_sha256 = if release_dir.exists() {
// Release already present in the cache
None
} else {
Some((github_release_download_url(&release_semver), None))
};
(release_semver, download_url_and_sha256, release_dir)
}
config.explicit_release =
Some(ExplicitRelease::Semver(release_semver.clone()));

let release_dir = config.release_dir(&release_semver);
let download_url_and_sha256 = if release_dir.exists() {
// Release already present in the cache
None
} else {
Some((github_release_download_url(&release_semver), None))
};
(release_semver, download_url_and_sha256, release_dir)
}
}
}
Expand Down

0 comments on commit ec0ddc9

Please sign in to comment.