From 0ceb97538adc4caaa9f067a7788d1c73b4098604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Thu, 28 Oct 2021 15:00:50 +0200 Subject: [PATCH] BackupGroup: add filter helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to have a single implementation of "group is matched by group filter". Signed-off-by: Fabian Grünbichler Reviewed-by: Dominik Csapak Signed-off-by: Thomas Lamprecht --- pbs-datastore/src/backup_info.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs index b94b9779..9f56e924 100644 --- a/pbs-datastore/src/backup_info.rs +++ b/pbs-datastore/src/backup_info.rs @@ -1,5 +1,6 @@ use std::os::unix::io::RawFd; use std::path::{Path, PathBuf}; +use std::str::FromStr; use anyhow::{bail, format_err, Error}; @@ -10,6 +11,7 @@ use pbs_api_types::{ GROUP_PATH_REGEX, SNAPSHOT_PATH_REGEX, BACKUP_FILE_REGEX, + GroupFilter, }; use super::manifest::MANIFEST_BLOB_NAME; @@ -155,6 +157,17 @@ impl BackupGroup { 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 {