Skip to main content
← dvs documentation Rust API reference

dvs/backends/
mod.rs

1use std::path::{Path, PathBuf};
2
3use crate::Hashes;
4use crate::audit::AuditEntry;
5use crate::config::Compression;
6use anyhow::Result;
7
8pub mod local;
9
10pub trait Backend: Send + Sync {
11    /// Check whether the backend has already been initialized.
12    fn is_initialized(&self) -> Result<bool>;
13
14    /// Initialize the backend storage (create directories, set permissions, etc.)
15    fn init(&self) -> Result<()>;
16
17    /// Store file to backend by hash, optionally compressing.
18    /// Returns the stored (compressed) size in bytes.
19    fn store(
20        &self,
21        hash: &Hashes,
22        source: &Path,
23        compression: Compression,
24        on_bytes: Option<&(dyn Fn(u64) + Send + Sync)>,
25    ) -> Result<u64>;
26
27    /// Retrieve content by hash to target path, optionally decompressing.
28    /// Returns true if the file was copied to the target path.
29    fn retrieve(
30        &self,
31        hash: &Hashes,
32        target: &Path,
33        compression: Compression,
34        on_bytes: Option<&(dyn Fn(u64) + Send + Sync)>,
35    ) -> Result<bool>;
36
37    /// Check if the file exists in the backend
38    fn exists(&self, hash: &Hashes) -> Result<bool>;
39
40    /// Remove content by hash (for rollback). Best-effort, may silently fail.
41    fn remove(&self, hash: &Hashes) -> Result<()>;
42
43    /// Log an audit entry to the backend's audit log.
44    fn log_audit(&self, entry: &AuditEntry) -> Result<()>;
45
46    /// Read the whole audit file, filtered by the given file paths.
47    /// If `files` is empty, return the full audit log
48    fn read_audit_file(&self, files: &[PathBuf]) -> Result<Vec<AuditEntry>>;
49}