aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.rs
diff options
context:
space:
mode:
authorGravatar BanceDev 2026-02-26 17:34:49 -0500
committerGravatar BanceDev 2026-02-26 17:34:49 -0500
commit44388f8de44ba13f740a5fc7e0f838c961fad084 (patch)
treeca0e92573e6e4e52ee2c22475ec5dcbe6dd8f60b /src/util.rs
parentproper config command handling (diff)
begin permissions shift for build commands
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/util.rs b/src/util.rs
index 90aacb6..e79124d 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,4 +1,3 @@
-use libc;
use std::env;
use std::fs;
use std::io;
@@ -28,8 +27,24 @@ pub fn get_editor() -> String {
.unwrap_or_else(|_| "nano".to_string())
}
-pub fn is_root() -> bool {
- unsafe { libc::geteuid() == 0 }
+pub fn get_invoking_user_env() -> Option<(u32, u32, String, String)> {
+ let username = std::env::var("SUDO_USER").ok()?;
+ if username.is_empty() {
+ return None;
+ }
+
+ let user = nix::unistd::User::from_name(&username).ok()??;
+ let uid = user.uid.as_raw();
+ let gid = user.gid.as_raw();
+ let home = user.dir.to_string_lossy().to_string();
+
+ // Reconstruct a sane PATH for the user including common tool locations
+ let path = format!(
+ "{home}/.cargo/bin:{home}/.local/bin:/usr/local/bin:/usr/bin:/bin",
+ home = home
+ );
+
+ Some((uid, gid, home, path))
}
pub fn open_in_editor(editor: &str, file: &str) -> Result<(), String> {