use objects::error::HeddleError;
pub type Result<T> = std::result::Result<T, MountError>;
#[derive(Debug, thiserror::Error)]
pub enum MountError {
#[error("not found: {0}")]
NotFound(String),
#[error("stale node: {0}")]
Stale(String),
#[error("not a directory: {0}")]
NotADirectory(String),
#[error("thread {0} has no current state")]
UnknownThread(String),
#[error("read-only filesystem")]
ReadOnly,
#[error(transparent)]
Store(#[from] HeddleError),
}
impl MountError {
pub fn to_errno(&self) -> i32 {
match self {
MountError::NotFound(_) | MountError::UnknownThread(_) => libc::ENOENT,
MountError::Stale(_) => libc::ESTALE,
MountError::NotADirectory(_) => libc::ENOTDIR,
MountError::ReadOnly => libc::EROFS,
MountError::Store(HeddleError::NotFound(_))
| MountError::Store(HeddleError::StateNotFound(_))
| MountError::Store(HeddleError::MissingObject { .. }) => libc::ENOENT,
MountError::Store(HeddleError::Io(io)) => io.raw_os_error().unwrap_or(libc::EIO),
MountError::Store(_) => libc::EIO,
}
}
}