use super::{BackupLayoutGuard, JournalLockError, PersistenceError, immutable_record};
use crate::model::{
artifacts::ArtifactChecksumRecord,
effect_graph::{EffectGraphRecord, MAX_EFFECT_GRAPH_BYTES},
};
use thiserror::Error;
pub fn create_effect_graph(
layout: &BackupLayoutGuard,
record: &EffectGraphRecord,
) -> Result<(), EffectGraphPersistenceError> {
immutable_record::create(layout, "effect-graph.json", MAX_EFFECT_GRAPH_BYTES, record)
}
pub fn read_effect_graph(
layout: &BackupLayoutGuard,
expected: &ArtifactChecksumRecord,
) -> Result<EffectGraphRecord, EffectGraphPersistenceError> {
immutable_record::read(
layout,
"effect-graph.json",
MAX_EFFECT_GRAPH_BYTES,
|record: &EffectGraphRecord| &record.digest() == expected,
|| EffectGraphPersistenceError::DigestMismatch,
)
}
#[derive(Debug, Error)]
pub enum EffectGraphPersistenceError {
#[error("effect graph digest mismatch")]
DigestMismatch,
#[error(transparent)]
Lock(#[from] JournalLockError),
#[error(transparent)]
Persistence(#[from] PersistenceError),
}
#[cfg(all(test, unix))]
mod tests;