[pbs-devel] [PATCH v3 proxmox-backup 03/11] BackupGroup: add filter helper

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Oct 28 15:00:50 CEST 2021


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

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---

Notes:
    v2->v3: rename `filter` fn to `matches`
    
    there might be a better place for this if we want to support more complex
    filters in the future (like, exists in local datastore, or has > X snapshots,
    ..)

 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 {
-- 
2.30.2






More information about the pbs-devel mailing list