From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 261AC6A4A2
 for <pve-devel@lists.proxmox.com>; Thu, 16 Sep 2021 16:47:20 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 1A01A26E18
 for <pve-devel@lists.proxmox.com>; Thu, 16 Sep 2021 16:46:50 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 9AF1D26E0D
 for <pve-devel@lists.proxmox.com>; Thu, 16 Sep 2021 16:46:49 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 73EAF44903;
 Thu, 16 Sep 2021 16:46:49 +0200 (CEST)
Message-ID: <77163464-e42c-bc65-231e-3c3d319ed967@proxmox.com>
Date: Thu, 16 Sep 2021 16:46:48 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:93.0) Gecko/20100101
 Thunderbird/93.0
Content-Language: en-US
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 =?UTF-8?Q?Fabian_Gr=c3=bcnbichler?= <f.gruenbichler@proxmox.com>
References: <20210915134157.19762-1-f.gruenbichler@proxmox.com>
 <20210915134157.19762-4-f.gruenbichler@proxmox.com>
From: Dominik Csapak <d.csapak@proxmox.com>
In-Reply-To: <20210915134157.19762-4-f.gruenbichler@proxmox.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 1.233 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 NICE_REPLY_A           -1.698 Looks like a legit reply (A)
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH v2 proxmox-backup 03/10] BackupGroup: add
 filter helper
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 16 Sep 2021 14:47:20 -0000

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