#[cfg(not(target_os = "macos"))]
pub(crate) mod unsupported;
#[cfg(target_os = "macos")]
pub(crate) use crate::bridge::ffi;
#[cfg(not(target_os = "macos"))]
pub(crate) use self::unsupported as ffi;
use crate::containerization;
use crate::containerization::linux_container;
use crate::containerization_extras::ProgressHandler;
use crate::error::Error;
use std::sync::Mutex;
use std::time::Duration;
use std::time::SystemTime;
pub(crate) struct Progress(pub(crate) Option<ProgressHandler>);
type ConfigureContainer = Box<dyn FnOnce(&mut linux_container::Configuration) + Send>;
pub(crate) struct Configure(pub(crate) Mutex<Option<ConfigureContainer>>);
impl Configure {
pub(crate) fn new(configure: impl FnOnce(&mut linux_container::Configuration) + Send + 'static) -> Self {
Self(Mutex::new(Some(Box::new(configure))))
}
}
pub(crate) fn outcome(outcome: ffi::CzOutcome, action: impl Into<String>) -> Result<ffi::CzOutcome, Error> {
match outcome.error() {
Some(message) => Err(error(action, message)),
None => Ok(outcome),
}
}
#[cfg(target_os = "macos")]
fn error(action: impl Into<String>, message: String) -> Error {
Error::failed(action, message)
}
#[cfg(not(target_os = "macos"))]
fn error(action: impl Into<String>, message: String) -> Error {
Error::unavailable(action, message)
}
pub(crate) fn exit_status(outcome: &ffi::CzOutcome) -> containerization::ExitStatus {
containerization::ExitStatus {
exit_code: outcome.exit_code(),
exited_at: SystemTime::UNIX_EPOCH + Duration::from_secs_f64(outcome.exited_at().max(0.0)),
}
}