khive_db/
database_owner_identity.rs1#[cfg(any(unix, windows))]
4use crate::file_identity::DatabaseFileIdentity;
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
9pub struct DatabaseOwnerIdentity {
10 pub(crate) durable_id: uuid::Uuid,
11 #[cfg(any(unix, windows))]
12 pub(crate) file_identity: DatabaseFileIdentity,
13}
14
15impl DatabaseOwnerIdentity {
16 pub fn durable_id(&self) -> uuid::Uuid {
18 self.durable_id
19 }
20
21 #[cfg(any(unix, windows))]
23 pub fn file_identity(&self) -> DatabaseFileIdentity {
24 self.file_identity
25 }
26
27 pub(crate) fn verify_owner(&self, expected: &Self) -> Result<(), DatabaseOwnerIdentityError> {
28 if self != expected {
29 return Err(DatabaseOwnerIdentityError::OwnerMismatch);
30 }
31 Ok(())
32 }
33}
34
35#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
37pub enum DatabaseOwnerIdentityError {
38 #[error("an in-memory database cannot own a durable filesystem root")]
39 InMemory,
40 #[error("the opened database has no installed durable identity; reopen after installation")]
41 DurableIdentityUnavailable,
42 #[error("the opened database has no validated physical file identity")]
43 PhysicalIdentityUnavailable,
44 #[error("physical database ownership identity is unsupported on this platform")]
45 UnsupportedPlatform,
46 #[error("the stored database identity or opened file identity does not match the owner")]
47 OwnerMismatch,
48}