use std::path::Path;
use engenho_store::data_dir_lock::{DataDirLock, LockError};
use crate::boot::BootPhase;
use crate::error::RuntimeError;
use crate::runtime::STORE_DIR;
#[derive(Debug)]
#[non_exhaustive]
pub struct StoreReleased;
impl StoreReleased {
pub(crate) const fn minted() -> Self {
Self
}
pub fn probe(data_dir: &Path, durable: bool) -> Result<Self, LockError> {
if durable {
drop(DataDirLock::acquire(data_dir.join(STORE_DIR))?);
}
Ok(Self)
}
}
#[derive(Debug)]
pub enum BootUnwind {
NeverOpened,
Released(StoreReleased),
StillShared {
strong_count: usize,
},
TerminateFailed(Box<RuntimeError>),
}
impl BootUnwind {
#[must_use]
pub const fn store_released(&self) -> bool {
matches!(self, Self::Released(_))
}
}
#[derive(Debug)]
pub struct BootFailed {
pub error: RuntimeError,
pub phase: BootPhase,
pub unwind: BootUnwind,
}
impl std::fmt::Display for BootFailed {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.error, f)
}
}
impl std::error::Error for BootFailed {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.error)
}
}