use crate::error::FrostxError;
use std::path::Path;
use uuid::Uuid;
pub trait BackupBackend: Send + Sync {
fn check(&self, uuid: Uuid) -> Result<bool, FrostxError>;
fn upload(&self, uuid: Uuid, archive_path: &Path) -> Result<String, FrostxError>;
fn verify(&self, uuid: Uuid, local_archive: &std::path::Path) -> Result<bool, FrostxError>;
}
pub type BackendFactory = fn(&str) -> Box<dyn BackupBackend>;
pub mod rsync;
const ALL_BACKENDS: &[&[(&str, BackendFactory)]] = &[rsync::REGISTRY];
pub fn from_url(server: &str) -> Result<Box<dyn BackupBackend>, FrostxError> {
for registry in ALL_BACKENDS {
for (scheme, factory) in *registry {
if server.starts_with(scheme) {
return Ok(factory(server));
}
}
}
let supported: Vec<&str> = ALL_BACKENDS
.iter()
.flat_map(|r| r.iter().map(|(s, _)| *s))
.collect();
Err(FrostxError::Config(format!(
"unsupported backup server scheme in '{server}': expected one of {}",
supported.join(", ")
)))
}