use crate::global::{ChrootUnverified, ChrootVerified};
use crate::GlobalsFinal;
use anyhow::Result as AResult;
use btrfs::BtrfsBackend;
use none::NoneBackend;
use serde::Deserialize;
use std::path::Path;
mod btrfs;
mod none;
pub(super) trait BackendOps {
fn make_blank(&mut self) -> AResult<()>;
fn duplicate(&mut self, source: ChrootVerified) -> AResult<()>;
fn delete(&mut self) -> AResult<()>;
}
pub(super) trait BackendMarker {}
#[derive(Deserialize, Copy, Clone, Default)]
pub enum BackendTypes {
#[default]
#[serde(rename = "none")]
None,
#[serde(rename = "btrfs")]
Btrfs,
}
impl BackendTypes {
pub(super) fn target(&self, target: &Path, globals: &GlobalsFinal) -> Box<dyn BackendOps> {
match self {
Self::None => Box::new(NoneBackend::new(target, globals)),
Self::Btrfs => Box::new(BtrfsBackend::new(target, globals)),
}
}
}
pub(super) struct Snapshot<T: BackendMarker> {
target: Option<ChrootUnverified>,
dry_run: bool,
marker: std::marker::PhantomData<T>,
}
impl<T: BackendMarker> Snapshot<T> {
pub(super) fn new(target: &Path, globals: &GlobalsFinal) -> Self {
let target = Some(globals.chroot(target));
let dry_run = globals.dry_run();
let marker = std::marker::PhantomData;
Self {
target,
dry_run,
marker,
}
}
}