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_with(
48 layout,
49 "operation-plan.json",
50 MAX_OPERATION_PLAN_BYTES,
51 |record: &OperationPlanRecord| {
52 if &record.digest() != expected {
53 return Err(OperationPlanPersistenceError::DigestMismatch);
54 }
55 Ok(())
56 },
57 )
58}
59
60#[derive(Debug, Error)]
62pub enum OperationPlanPersistenceError {
63 #[error("operation plan digest mismatch")]
65 DigestMismatch,
66 #[error(transparent)]
68 Lock(#[from] JournalLockError),
69 #[error(transparent)]
71 Persistence(#[from] PersistenceError),
72}
73
74#[cfg(all(test, unix))]
75mod tests;