From a2773ddd799fbc1e628b07ee1f1468509f8ff5b6 Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Fri, 22 Nov 2024 11:30:07 +0100 Subject: [PATCH] datastore: move `ArchiveType` to api types Moving the `ArchiveType` to avoid crate dependencies on `pbs-datastore`. In preparation for introducing a dedicated `BackupArchiveName` api type, allowing to set the corresponding archive type variant when parsing the archive name based on it's filename. Signed-off-by: Christian Ebner --- pbs-api-types/src/datastore.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs index 3d2b0eab..3b9c206d 100644 --- a/pbs-api-types/src/datastore.rs +++ b/pbs-api-types/src/datastore.rs @@ -1,5 +1,5 @@ use std::fmt; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use anyhow::{bail, format_err, Error}; use const_format::concatcp; @@ -1644,3 +1644,24 @@ impl BackupGroupDeleteStats { self.protected_snapshots += 1; } } + +#[derive(PartialEq, Eq)] +/// Allowed variants of backup archives to be contained in a snapshot's manifest +pub enum ArchiveType { + FixedIndex, + DynamicIndex, + Blob, +} + +impl ArchiveType { + pub fn from_path(archive_name: impl AsRef) -> Result { + let archive_name = archive_name.as_ref(); + let archive_type = match archive_name.extension().and_then(|ext| ext.to_str()) { + Some("didx") => ArchiveType::DynamicIndex, + Some("fidx") => ArchiveType::FixedIndex, + Some("blob") => ArchiveType::Blob, + _ => bail!("unknown archive type: {archive_name:?}"), + }; + Ok(archive_type) + } +}