From 51e75d6b990106fdf76c951021c1b14b6310fce1 Mon Sep 17 00:00:00 2001 From: Thomas Clement Date: Tue, 9 Dec 2025 20:21:34 +0100 Subject: [PATCH] Use SUDO_HOME environment variable to derive the pkgx directory if it is set. Without this, we might work on the root user directory (as seen on Linux). --- crates/lib/src/config.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/lib/src/config.rs b/crates/lib/src/config.rs index cdd76711d..1ec47b4e3 100644 --- a/crates/lib/src/config.rs +++ b/crates/lib/src/config.rs @@ -69,6 +69,14 @@ fn get_pkgx_dir() -> io::Result { } } + // Use sudoer home directory if it is set. + if let Ok(path) = env::var("SUDO_HOME") { + let path = PathBuf::from(path).join(".pkgx"); + if path.is_absolute() { + return Ok(path); + } + } + let default = dirs_next::home_dir().map(|x| x.join(".pkgx")); if default.clone().is_some_and(|x| x.exists()) {