Validate sudo access, prompting the user for their password if necessary
()
| 45 | |
| 46 | /// Validate sudo access, prompting the user for their password if necessary |
| 47 | fn 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 |
| 74 | pub fn wrap_with_sudo(mut cmd_builder: CommandBuilder) -> Result<CommandBuilder> { |
no test coverage detected