1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
use crate::store::stats::{
LockLeafSymlinkProtection, MmapAdmissionSummary, MmapEvidence, ParentDirSyncAdmissionSummary,
ParentDirSyncEvidence, StoreLockAdmissionSummary, StorePathStatusEvidence,
};
/// Store open mode for lifetime-held directory locking.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum StoreLockMode {
/// Mutable open: writer thread active, exclusive lock required.
Mutable,
/// Read-only open: no writer thread, but still exclusive under the
/// current store-ownership contract.
ReadOnly,
}
/// Typed reason a persisted platform profile was rejected.
#[derive(Debug)]
#[non_exhaustive]
pub enum ProfileInvalidKind {
/// Reading the profile file failed.
Io(std::io::Error),
/// Decoding the JSON profile failed.
DecodeJson(serde_json::Error),
/// Encoding the canonical fingerprint body failed.
FingerprintEncode(serde_json::Error),
/// The profile schema version is not supported by this crate.
UnsupportedSchemaVersion {
/// Version observed in the profile.
observed: u16,
/// Version this crate accepts.
expected: u16,
},
/// The stored fingerprint did not match the computed fingerprint.
FingerprintMismatch {
/// Fingerprint stored in the profile.
observed: u32,
/// Fingerprint computed from the profile body.
computed: u32,
},
/// Store-lock admission contradicts the observed lock evidence.
InconsistentLockAdmission {
/// Admission recorded in the profile.
admission: StoreLockAdmissionSummary,
/// Evidence recorded in the profile.
evidence: LockLeafSymlinkProtection,
},
/// Parent-directory sync admission contradicts the observed evidence.
InconsistentParentDirSyncAdmission {
/// Admission recorded in the profile.
admission: ParentDirSyncAdmissionSummary,
/// Evidence recorded in the profile.
evidence: ParentDirSyncEvidence,
},
/// mmap evidence contradicts the store-path status.
InconsistentMmapPath {
/// Profile field whose evidence was inconsistent.
field: &'static str,
/// Evidence recorded in the profile.
evidence: MmapEvidence,
/// Evidence required by the path status.
expected: MmapEvidence,
/// Path status that determined the expected evidence.
path_status: StorePathStatusEvidence,
},
/// mmap admission contradicts the observed mmap evidence.
InconsistentMmapAdmission {
/// Profile field whose admission was inconsistent.
field: &'static str,
/// Admission recorded in the profile.
admission: MmapAdmissionSummary,
/// Evidence recorded in the profile.
evidence: MmapEvidence,
},
}
impl std::fmt::Display for ProfileInvalidKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Io(error) => write!(f, "{error}"),
Self::DecodeJson(error) | Self::FingerprintEncode(error) => write!(f, "{error}"),
Self::UnsupportedSchemaVersion { observed, expected } => write!(
f,
"schema_version {observed} is not supported; expected {expected}"
),
Self::FingerprintMismatch { observed, computed } => write!(
f,
"fingerprint_crc32 {observed} does not match computed {computed}"
),
Self::InconsistentLockAdmission {
admission,
evidence,
} => write!(
f,
"store_lock admission {admission:?} is inconsistent with lock evidence {evidence:?}"
),
Self::InconsistentParentDirSyncAdmission {
admission,
evidence,
} => write!(
f,
"parent_dir_sync admission {admission:?} is inconsistent with evidence {evidence:?}"
),
Self::InconsistentMmapPath {
field,
evidence,
expected,
path_status,
} => write!(
f,
"{field} evidence {evidence:?} is inconsistent with path_status {path_status:?}; expected {expected:?}"
),
Self::InconsistentMmapAdmission {
field,
admission,
evidence,
} => write!(
f,
"{field} admission {admission:?} is inconsistent with mmap evidence {evidence:?}"
),
}
}
}
impl ProfileInvalidKind {
pub(super) fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(error) => Some(error),
Self::DecodeJson(error) | Self::FingerprintEncode(error) => Some(error),
Self::UnsupportedSchemaVersion { .. }
| Self::FingerprintMismatch { .. }
| Self::InconsistentLockAdmission { .. }
| Self::InconsistentParentDirSyncAdmission { .. }
| Self::InconsistentMmapPath { .. }
| Self::InconsistentMmapAdmission { .. } => None,
}
}
}