use super::super::store::Store;
use super::*;
const STORE: Store = Store("files");
pub(super) fn directory(id: &str) -> Result<PathBuf, FileError> {
STORE.directory(id)
}
pub(super) fn create(request: &MutationRequest) -> Result<MutationReceipt, FileError> {
STORE.create(|id, path| MutationReceipt::new(id, request.clone(), path))
}
pub(super) fn save(receipt: &MutationReceipt) -> Result<(), FileError> {
STORE.save(&receipt.operation_id, &receipt.receipt_path, receipt)
}
pub(super) fn load(id: &str) -> Result<MutationReceipt, FileError> {
let receipt: MutationReceipt = STORE.load(id)?;
if receipt.operation_id != id
|| STORE.directory(id)?.join("receipt.json").to_str() != Some(&receipt.receipt_path)
{
return Err(FileError::new(
FileErrorCode::Internal,
"receipt identity/path mismatch",
));
}
Ok(receipt)
}
pub(super) fn claim(id: &str) -> Result<(), FileError> {
STORE.claim(id)
}