From f780ef0b7f1adc6249fee6e21c021ae17bdcf956 Mon Sep 17 00:00:00 2001 From: ripytide Date: Thu, 7 Nov 2024 16:56:09 +0000 Subject: [PATCH] fix: make the use of sudo only work on unix systems --- src/cmd.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cmd.rs b/src/cmd.rs index e268714..227e1cb 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -26,10 +26,14 @@ where S: Into, I: IntoIterator, { - let we_are_root = { - let uid = unsafe { libc::geteuid() }; - uid == 0 - }; + #[cfg(unix)] + let use_sudo = matches!(perms, Perms::Sudo) && unsafe { libc::geteuid() } != 0; + #[cfg(windows)] + if matches!(perms, Perms::Sudo) { + return eyre!("sudo for privilege escalation is not supported on windows"); + } + #[cfg(windows)] + let use_sudo = false; let args: Vec = args.into_iter().map(Into::into).collect::>(); @@ -38,7 +42,7 @@ where } let args = Some("sudo".to_string()) - .filter(|_| matches!(perms, Perms::Sudo) && !we_are_root) + .filter(|_| use_sudo) .into_iter() .chain(args) .collect::>();