BackupGroup: add filter helper

to have a single implementation of "group is matched by group filter".

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-10-28 15:00:50 +02:00 committed by Thomas Lamprecht
parent 3e276f6fb6
commit 0ceb97538a
1 changed files with 13 additions and 0 deletions

View File

@ -1,5 +1,6 @@
use std::os::unix::io::RawFd; use std::os::unix::io::RawFd;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::FromStr;
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
@ -10,6 +11,7 @@ use pbs_api_types::{
GROUP_PATH_REGEX, GROUP_PATH_REGEX,
SNAPSHOT_PATH_REGEX, SNAPSHOT_PATH_REGEX,
BACKUP_FILE_REGEX, BACKUP_FILE_REGEX,
GroupFilter,
}; };
use super::manifest::MANIFEST_BLOB_NAME; use super::manifest::MANIFEST_BLOB_NAME;
@ -155,6 +157,17 @@ impl BackupGroup {
Ok(last) Ok(last)
} }
pub fn matches(&self, filter: &GroupFilter) -> bool {
match filter {
GroupFilter::Group(backup_group) => match BackupGroup::from_str(&backup_group) {
Ok(group) => &group == self,
Err(_) => false, // shouldn't happen if value is schema-checked
},
GroupFilter::BackupType(backup_type) => self.backup_type() == backup_type,
GroupFilter::Regex(regex) => regex.is_match(&self.to_string()),
}
}
} }
impl std::fmt::Display for BackupGroup { impl std::fmt::Display for BackupGroup {