Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit f390f2e

Browse files
qcloutierr-darwish
andauthored
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. sdkman/sdkman-cli#1042 * Fix macOS build; simplify Co-authored-by: Roey Darwish Dror <[email protected]>
1 parent d864199 commit f390f2e

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ notify-rust = "4.5.0"
4141

4242
[target.'cfg(unix)'.dependencies]
4343
nix = "0.24.1"
44+
rust-ini = "0.18.0"
4445
self_update_crate = { version = "0.30.0", default-features = false, optional = true, package = "self_update", features = ["archive-tar", "compression-flate2", "rustls"] }
4546

4647
[target.'cfg(windows)'.dependencies]
4748
self_update_crate = { version = "0.30.0", default-features = false, optional = true, package = "self_update", features = ["archive-zip", "compression-zip-deflate", "rustls"] }
4849
winapi = "0.3.9"
4950
parselnk = "0.1.0"
5051

51-
[target.'cfg(target_os = "linux")'.dependencies]
52-
rust-ini = "0.18.0"
53-
5452
[profile.release]
5553
lto = true
5654

src/steps/os/unix.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::utils::{require, PathExt};
88
use crate::Step;
99
use anyhow::Result;
1010
use directories::BaseDirs;
11+
use ini::Ini;
1112
use log::debug;
1213
use std::fs;
1314
use std::os::unix::fs::MetadataExt;
@@ -343,11 +344,26 @@ pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Res
343344

344345
print_separator("SDKMAN!");
345346

346-
let cmd_selfupdate = format!("source {} && sdk selfupdate", &sdkman_init_path);
347-
run_type
348-
.execute(&bash)
349-
.args(&["-c", cmd_selfupdate.as_str()])
350-
.check_run()?;
347+
let sdkman_config_path = env::var("SDKMAN_DIR")
348+
.map(PathBuf::from)
349+
.unwrap_or_else(|_| base_dirs.home_dir().join(".sdkman"))
350+
.join("etc")
351+
.join("config")
352+
.require()?;
353+
354+
let sdkman_config = Ini::load_from_file(sdkman_config_path)?;
355+
let selfupdate_enabled = sdkman_config
356+
.general_section()
357+
.get("sdkman_selfupdate_feature")
358+
.unwrap_or("false");
359+
360+
if selfupdate_enabled == "true" {
361+
let cmd_selfupdate = format!("source {} && sdk selfupdate", &sdkman_init_path);
362+
run_type
363+
.execute(&bash)
364+
.args(&["-c", cmd_selfupdate.as_str()])
365+
.check_run()?;
366+
}
351367

352368
let cmd_update = format!("source {} && sdk update", &sdkman_init_path);
353369
run_type.execute(&bash).args(&["-c", cmd_update.as_str()]).check_run()?;

0 commit comments

Comments
 (0)