ic_backup/ops/persistence/operation_plan/
mod.rs1use super::{BackupLayoutGuard, JournalLockError, PersistenceError, immutable_record};
4use crate::model::{
5 artifacts::ArtifactChecksumRecord,
6 operation_plan::{MAX_OPERATION_PLAN_BYTES, OperationPlanRecord},
7};
8use thiserror::Error;
9
10pub fn create_operation_plan(
18 layout: &BackupLayoutGuard,
19 record: &OperationPlanRecord,
20) -> Result<(), OperationPlanPersistenceError> {
21 immutable_record::create(
22 layout,
23 "operation-plan.json",
24 MAX_OPERATION_PLAN_BYTES,
25 record,
26 )
27}
28
29pub(super) fn create_encoded(
30 layout: &BackupLayoutGuard,
31 bytes: &[u8],
32) -> Result<(), OperationPlanPersistenceError> {
33 immutable_record::create_encoded_record(layout, "operation-plan.json", bytes)
34}
35
36pub fn read_operation_plan(
44 layout: &BackupLayoutGuard,
45 expected: &ArtifactChecksumRecord,
46) -> Result<OperationPlanRecord, OperationPlanPersistenceError> {
47 immutable_record::read(
48 layout,
49 "operation-plan.json",
50 MAX_OPERATION_PLAN_BYTES,
51 |record: &OperationPlanRecord| &record.digest() == expected,
52 || OperationPlanPersistenceError::DigestMismatch,
53 )
54}
55
56#[derive(Debug, Error)]
58pub enum OperationPlanPersistenceError {
59 #[error("operation plan digest mismatch")]
61 DigestMismatch,
62 #[error(transparent)]
64 Lock(#[from] JournalLockError),
65 #[error(transparent)]
67 Persistence(#[from] PersistenceError),
68}
69
70#[cfg(all(test, unix))]
71mod tests;