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 <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2024-11-22 11:30:07 +01:00 committed by Fabian Grünbichler
parent fda1f99479
commit a2773ddd79

View File

@ -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<Path>) -> Result<Self, Error> {
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)
}
}