MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / validate_sudo_access

Function validate_sudo_access

src/executor/helpers/run_with_sudo.rs:47–71  ·  view source on GitHub ↗

Validate sudo access, prompting the user for their password if necessary

()

Source from the content-addressed store, hash-verified

45
46/// Validate sudo access, prompting the user for their password if necessary
47fn validate_sudo_access() -> Result<()> {
48 let needs_password =
49 IsTerminal::is_terminal(&std::io::stdout()) && !sudo_runs_without_password();
50
51 if needs_password {
52 suspend_progress_bar(|| {
53 info!("Sudo privileges are required to continue.");
54
55 // Validate and cache sudo credentials
56 let auth_status = Command::new("sudo")
57 .arg("--validate") // Validate and extend the timeout
58 .stdin(Stdio::inherit())
59 .stdout(Stdio::inherit())
60 .stderr(Stdio::inherit())
61 .status()
62 .map_err(|_| anyhow!("Failed to authenticate with sudo"))?;
63
64 if !auth_status.success() {
65 bail!("Failed to authenticate with sudo");
66 }
67 Ok(())
68 })?;
69 }
70 Ok(())
71}
72
73/// Wrap with sudo if not running as root
74pub fn wrap_with_sudo(mut cmd_builder: CommandBuilder) -> Result<CommandBuilder> {

Callers 1

wrap_with_sudoFunction · 0.85

Calls 3

suspend_progress_barFunction · 0.85
argMethod · 0.80

Tested by

no test coverage detected