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