[pve-devel] [PATCH v2 proxmox-backup 03/10] BackupGroup: add filter helper

Dominik Csapak d.csapak at proxmox.com
Thu Sep 16 16:46:48 CEST 2021


On 9/15/21 15:41, Fabian Grünbichler wrote:
> to have a single implementation of "group is matched by group filter".
> 
> Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
> ---
> 
> Notes:
>      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 | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs
> index f77098ee..416a5e32 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;
> @@ -153,6 +155,14 @@ impl BackupGroup {
>   
>           Ok(last)
>       }
> +
> +    pub fn filter(&self, filter: &GroupFilter) -> bool {
> +        match filter {
> +            GroupFilter::Group(backup_group) => &BackupGroup::from_str(&backup_group).unwrap() == self,

if you'd parse the backup group already in the api type, this would not 
be necessary

> +            GroupFilter::BackupType(backup_type) => self.backup_type() == backup_type,
> +            GroupFilter::Regex(regex) => regex.is_match(&format!("{}", self)),

wouldn't &self.to_string() not better?

> +        }
> +    }
>   }
>   
>   impl std::fmt::Display for BackupGroup {
> 






More information about the pve-devel mailing list