diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs index 92579f61..de4d51a1 100644 --- a/pbs-api-types/src/datastore.rs +++ b/pbs-api-types/src/datastore.rs @@ -471,7 +471,7 @@ impl std::cmp::PartialOrd for BackupType { "backup-id": { schema: BACKUP_ID_SCHEMA }, }, )] -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] /// A backup group (without a data store). pub struct BackupGroup { @@ -488,6 +488,28 @@ impl BackupGroup { pub fn new>(ty: BackupType, id: T) -> Self { Self { ty, id: id.into() } } + + pub fn matches(&self, filter: &crate::GroupFilter) -> bool { + use crate::GroupFilter; + + match filter { + GroupFilter::Group(backup_group) => { + match backup_group.parse::() { + Ok(group) => *self == group, + Err(_) => false, // shouldn't happen if value is schema-checked + } + } + GroupFilter::BackupType(backup_type) => self.ty.as_str() == backup_type, + GroupFilter::Regex(regex) => regex.is_match(&self.to_string()), + } + } +} + +impl AsRef for BackupGroup { + #[inline] + fn as_ref(&self) -> &Self { + self + } } impl From<(BackupType, String)> for BackupGroup { @@ -568,6 +590,20 @@ pub struct BackupDir { pub time: i64, } +impl AsRef for BackupDir { + #[inline] + fn as_ref(&self) -> &BackupGroup { + &self.group + } +} + +impl AsRef for BackupDir { + #[inline] + fn as_ref(&self) -> &Self { + self + } +} + impl From<(BackupGroup, i64)> for BackupDir { fn from(data: (BackupGroup, i64)) -> Self { Self { diff --git a/pbs-api-types/src/jobs.rs b/pbs-api-types/src/jobs.rs index 654c0477..e859e755 100644 --- a/pbs-api-types/src/jobs.rs +++ b/pbs-api-types/src/jobs.rs @@ -342,6 +342,7 @@ pub struct TapeBackupJobStatus { /// Filter for matching `BackupGroup`s, for use with `BackupGroup::filter`. pub enum GroupFilter { /// BackupGroup type - either `vm`, `ct`, or `host`. + // FIXME: Should be `BackupType` BackupType(String), /// Full identifier of BackupGroup, including type Group(String),