liblitho 0.2.0

cli tool to flash/clone the images to storage devices
Documentation
//! macOS privilege elevation (not yet automated).

use crate::platform::traits::{ElevationCapability, PrivilegeOps};

use super::MacPlatform;

impl PrivilegeOps for MacPlatform {
    fn elevation_method() -> &'static str {
        "unsupported"
    }

    fn is_elevated() -> bool {
        // SAFETY: geteuid has no preconditions and is always safe to call.
        unsafe { libc::geteuid() == 0 }
    }

    fn elevation_capability() -> ElevationCapability {
        if Self::is_elevated() {
            ElevationCapability {
                ready: true,
                status_label: "elevated",
            }
        } else {
            ElevationCapability {
                ready: false,
                status_label: "elevation unsupported",
            }
        }
    }

    fn validate_elevation_prerequisites() -> Result<(), String> {
        if Self::is_elevated() {
            Ok(())
        } else {
            Err(
                "Automatic elevation is not supported on macOS yet. \
                 Run litho-tui with sudo."
                    .into(),
            )
        }
    }

    fn elevation_dialog_lines() -> [&'static str; 3] {
        [
            "Flash and clone operations require root access.",
            "Automatic elevation is not available on macOS yet.",
            "Restart litho-tui with sudo to continue.",
        ]
    }

    fn relaunch_elevated(_mode: &str, _device: &str, _image: &str) -> Result<(), String> {
        Err("Privilege elevation is not supported on macOS yet.".into())
    }

    fn current_euid_or_0() -> u32 {
        // SAFETY: geteuid has no preconditions and is always safe to call.
        unsafe { libc::geteuid() }
    }
}