pub mod traits;
#[cfg(target_os = "linux")]
pub mod linux;
#[cfg(target_os = "macos")]
pub mod macos;
#[cfg(target_os = "windows")]
pub mod windows;
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
pub mod unsupported;
pub use traits::{
DeviceInventory, DevicePathOps, DeviceReader, DeviceSafety, DeviceWriter, ElevationCapability,
Platform, PrivilegeOps, VolumeOps,
};
#[cfg(target_os = "linux")]
pub type Active = linux::LinuxPlatform;
#[cfg(target_os = "windows")]
pub type Active = windows::WindowsPlatform;
#[cfg(target_os = "macos")]
pub type Active = macos::MacPlatform;
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
pub type Active = unsupported::UnsupportedPlatform;
use anyhow::Result;
pub struct PlatformDevice;
impl PlatformDevice {
pub fn new_reader(device_path: &str) -> Result<Box<dyn DeviceReader>> {
Ok(Box::new(Active::open_reader(device_path)?))
}
pub fn new_clone_reader(device_path: &str) -> Result<Box<dyn DeviceReader>> {
Self::new_verify_reader(device_path)
}
pub fn new_verify_reader(device_path: &str) -> Result<Box<dyn DeviceReader>> {
Ok(Box::new(Active::open_verify_reader(device_path)?))
}
pub fn new_writer(device_path: &str) -> Result<Box<dyn DeviceWriter>> {
Ok(Box::new(Active::open_writer(device_path)?))
}
}
pub fn elevation_method() -> &'static str {
Active::elevation_method()
}
pub fn is_elevated() -> bool {
Active::is_elevated()
}
pub fn elevation_capability() -> ElevationCapability {
Active::elevation_capability()
}
pub fn validate_elevation_prerequisites() -> Result<(), String> {
Active::validate_elevation_prerequisites()
}
pub fn relaunch_elevated(mode: &str, device: &str, image: &str) -> Result<(), String> {
Active::relaunch_elevated(mode, device, image)
}
pub fn elevation_dialog_lines() -> [&'static str; 3] {
Active::elevation_dialog_lines()
}
pub fn current_euid_or_0() -> u32 {
Active::current_euid_or_0()
}
pub(crate) fn elevated_cli_args(mode: &str, device: &str, image: &str) -> Vec<String> {
vec![
"--mode".into(),
mode.into(),
"--device".into(),
device.into(),
"--image".into(),
image.into(),
]
}