From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pbs-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 5D7FC1FF16F for <inbox@lore.proxmox.com>; Tue, 13 May 2025 15:52:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E5AAE33204; Tue, 13 May 2025 15:53:11 +0200 (CEST) From: Christian Ebner <c.ebner@proxmox.com> To: pbs-devel@lists.proxmox.com Date: Tue, 13 May 2025 15:52:43 +0200 Message-Id: <20250513135247.644260-17-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250513135247.644260-1-c.ebner@proxmox.com> References: <20250513135247.644260-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.029 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH v3 proxmox-backup 16/20] api: admin: move backup group list generation into helper X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion <pbs-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/> List-Post: <mailto:pbs-devel@lists.proxmox.com> List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Backup Server development discussion <pbs-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com> Move the logic to generate a backup group list given backup type or backup_id into a helper function. This allows to reuse the same logic for generating the list of groups for which to clear trashed items. No functional change intended. Signed-off-by: Christian Ebner <c.ebner@proxmox.com> --- src/api2/admin/datastore.rs | 53 ++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 3ea5b19f1..bc2d51612 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -507,6 +507,37 @@ pub async fn list_snapshots( .map_err(|err| format_err!("failed to await blocking task: {err}"))? } +fn groups_by_type_or_id( + datastore: Arc<DataStore>, + ns: &BackupNamespace, + backup_type: Option<BackupType>, + backup_id: Option<String>, +) -> Result<Vec<BackupGroup>, Error> { + // FIXME: filter also owner before collecting, for doing that nicely the owner should move into + // backup group and provide an error free (Err -> None) accessor + match (backup_type, backup_id) { + (Some(backup_type), Some(backup_id)) => Ok(vec![datastore.backup_group_from_parts( + ns.clone(), + backup_type, + backup_id, + )]), + // FIXME: Recursion + (Some(backup_type), None) => Ok(datastore + .iter_backup_type_ok(ns.clone(), backup_type)? + .collect()), + // FIXME: Recursion + (None, Some(backup_id)) => Ok(BackupType::iter() + .filter_map(|backup_type| { + let group = + datastore.backup_group_from_parts(ns.clone(), backup_type, backup_id.clone()); + group.exists().then_some(group) + }) + .collect()), + // FIXME: Recursion + (None, None) => datastore.list_backup_groups(ns.clone()), + } +} + /// This must not run in a main worker thread as it potentially does tons of I/O. unsafe fn list_snapshots_blocking( store: String, @@ -528,27 +559,7 @@ unsafe fn list_snapshots_blocking( let datastore = DataStore::lookup_datastore(&store, Some(Operation::Read))?; - // FIXME: filter also owner before collecting, for doing that nicely the owner should move into - // backup group and provide an error free (Err -> None) accessor - let groups = match (backup_type, backup_id) { - (Some(backup_type), Some(backup_id)) => { - vec![datastore.backup_group_from_parts(ns.clone(), backup_type, backup_id)] - } - // FIXME: Recursion - (Some(backup_type), None) => datastore - .iter_backup_type_ok(ns.clone(), backup_type)? - .collect(), - // FIXME: Recursion - (None, Some(backup_id)) => BackupType::iter() - .filter_map(|backup_type| { - let group = - datastore.backup_group_from_parts(ns.clone(), backup_type, backup_id.clone()); - group.exists().then_some(group) - }) - .collect(), - // FIXME: Recursion - (None, None) => datastore.list_backup_groups(ns.clone())?, - }; + let groups = groups_by_type_or_id(datastore, &ns, backup_type, backup_id)?; let info_to_snapshot_list_item = |group: &BackupGroup, owner, info: BackupInfo| { let backup = pbs_api_types::BackupDir { -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel