mithril_aggregator/services/snapshotter/
interface.rsuse std::io;
use std::path::{Path, PathBuf};
use thiserror::Error;
use mithril_common::StdResult;
use crate::ZstandardCompressionParameters;
#[cfg_attr(test, mockall::automock)]
pub trait Snapshotter: Sync + Send {
fn snapshot_all(&self, filepath: &Path) -> StdResult<OngoingSnapshot>;
fn snapshot_subset(&self, filepath: &Path, files: Vec<PathBuf>) -> StdResult<OngoingSnapshot>;
}
#[derive(Error, Debug)]
pub enum SnapshotError {
#[error("Create archive error: {0}")]
CreateArchiveError(#[from] io::Error),
#[error("Invalid archive error: {0}")]
InvalidArchiveError(String),
#[error("Archive verification error: {0}")]
VerifyArchiveError(String),
#[error("Upload file error: `{0}`")]
UploadFileError(String),
#[error("Snapshot General Error: `{0}`")]
GeneralError(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SnapshotterCompressionAlgorithm {
Gzip,
Zstandard(ZstandardCompressionParameters),
}
impl From<ZstandardCompressionParameters> for SnapshotterCompressionAlgorithm {
fn from(params: ZstandardCompressionParameters) -> Self {
Self::Zstandard(params)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OngoingSnapshot {
pub(super) filepath: PathBuf,
pub(super) filesize: u64,
}
impl OngoingSnapshot {
pub fn new(filepath: PathBuf, filesize: u64) -> Self {
Self { filepath, filesize }
}
pub fn get_file_path(&self) -> &PathBuf {
&self.filepath
}
pub fn get_file_size(&self) -> &u64 {
&self.filesize
}
}