From f390f2edbe74d1f1c635564efdf61a1dd4dd654b Mon Sep 17 00:00:00 2001 From: Quinton Cloutier <33400937+qcloutier@users.noreply.github.com> Date: Sat, 18 Jun 2022 08:29:37 -0300 Subject: [PATCH] Ensure `selfupdate` is enabled for SDKMAN! (#954) * Ensure `selfupdate` is enabled for SDKMAN! This subcommand is unavailable when the `sdkman_selfupdate_feature` option is disabled, as is the case when SDKMAN! is installed via Homebrew. https://github.com/sdkman/sdkman-cli/pull/1042 * Fix macOS build; simplify Co-authored-by: Roey Darwish Dror --- Cargo.toml | 4 +--- src/steps/os/unix.rs | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fa4cdcfd..1c63663a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ notify-rust = "4.5.0" [target.'cfg(unix)'.dependencies] nix = "0.24.1" +rust-ini = "0.18.0" self_update_crate = { version = "0.30.0", default-features = false, optional = true, package = "self_update", features = ["archive-tar", "compression-flate2", "rustls"] } [target.'cfg(windows)'.dependencies] @@ -48,9 +49,6 @@ self_update_crate = { version = "0.30.0", default-features = false, optional = t winapi = "0.3.9" parselnk = "0.1.0" -[target.'cfg(target_os = "linux")'.dependencies] -rust-ini = "0.18.0" - [profile.release] lto = true diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index e1bb5fcf..dd90b2d0 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -8,6 +8,7 @@ use crate::utils::{require, PathExt}; use crate::Step; use anyhow::Result; use directories::BaseDirs; +use ini::Ini; use log::debug; use std::fs; use std::os::unix::fs::MetadataExt; @@ -343,11 +344,26 @@ pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Res print_separator("SDKMAN!"); - let cmd_selfupdate = format!("source {} && sdk selfupdate", &sdkman_init_path); - run_type - .execute(&bash) - .args(&["-c", cmd_selfupdate.as_str()]) - .check_run()?; + let sdkman_config_path = env::var("SDKMAN_DIR") + .map(PathBuf::from) + .unwrap_or_else(|_| base_dirs.home_dir().join(".sdkman")) + .join("etc") + .join("config") + .require()?; + + let sdkman_config = Ini::load_from_file(sdkman_config_path)?; + let selfupdate_enabled = sdkman_config + .general_section() + .get("sdkman_selfupdate_feature") + .unwrap_or("false"); + + if selfupdate_enabled == "true" { + let cmd_selfupdate = format!("source {} && sdk selfupdate", &sdkman_init_path); + run_type + .execute(&bash) + .args(&["-c", cmd_selfupdate.as_str()]) + .check_run()?; + } let cmd_update = format!("source {} && sdk update", &sdkman_init_path); run_type.execute(&bash).args(&["-c", cmd_update.as_str()]).check_run()?;