From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id C5D3C1FF15C for ; Fri, 3 Oct 2025 10:51:10 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 844A01ED12; Fri, 3 Oct 2025 10:51:20 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Fri, 3 Oct 2025 10:50:36 +0200 Message-ID: <20251003085045.1346864-5-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251003085045.1346864-1-d.csapak@proxmox.com> References: <20251003085045.1346864-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -1.275 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 ENA_SUBJ_ODD_CASE 2.6 Subject has odd case KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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 proxmox-backup 3/6] api: admin: datastore: refactor BackupGroup to GroupListItem conversion X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" We will reuse this later. No functionial change intended. Signed-off-by: Dominik Csapak --- src/api2/admin/datastore.rs | 107 +++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 45 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index a098aca8e..26799de6e 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -142,57 +142,74 @@ pub fn list_groups( .try_fold(Vec::new(), |mut group_info, group| { let group = group?; - let owner = match datastore.get_owner(&ns, group.as_ref()) { - Ok(auth_id) => auth_id, - Err(err) => { - eprintln!( - "Failed to get owner of group '{}' in {} - {}", - group.group(), - print_store_and_ns(&store, &ns), - err - ); - return Ok(group_info); - } - }; - if !list_all && check_backup_owner(&owner, &auth_id).is_err() { - return Ok(group_info); + let item = + backup_group_to_group_list_item(datastore.clone(), group, &ns, &auth_id, list_all); + + if let Some(item) = item { + group_info.push(item); } - let snapshots = match group.list_backups() { - Ok(snapshots) => snapshots, - Err(_) => return Ok(group_info), - }; + Ok(group_info) + }) +} - let backup_count: u64 = snapshots.len() as u64; - if backup_count == 0 { - return Ok(group_info); - } +fn backup_group_to_group_list_item( + datastore: Arc, + group: pbs_datastore::BackupGroup, + ns: &BackupNamespace, + auth_id: &Authid, + list_all: bool, +) -> Option { + let owner = match datastore.get_owner(ns, group.as_ref()) { + Ok(auth_id) => auth_id, + Err(err) => { + eprintln!( + "Failed to get owner of group '{}' in {} - {}", + group.group(), + print_store_and_ns(datastore.name(), ns), + err + ); + return None; + } + }; + if !list_all && check_backup_owner(&owner, auth_id).is_err() { + return None; + } - let last_backup = snapshots - .iter() - .fold(&snapshots[0], |a, b| { - if a.is_finished() && a.backup_dir.backup_time() > b.backup_dir.backup_time() { - a - } else { - b - } - }) - .to_owned(); - - let notes_path = datastore.group_notes_path(&ns, group.as_ref()); - let comment = file_read_firstline(notes_path).ok(); - - group_info.push(GroupListItem { - backup: group.into(), - last_backup: last_backup.backup_dir.backup_time(), - owner: Some(owner), - backup_count, - files: last_backup.files, - comment, - }); + let snapshots = match group.list_backups() { + Ok(snapshots) => snapshots, + Err(_) => return None, + }; - Ok(group_info) + let backup_count: u64 = snapshots.len() as u64; + if backup_count == 0 { + return None; + } + + let last_backup = snapshots + .iter() + .fold(&snapshots[0], |a, b| { + if a.is_finished() && a.backup_dir.backup_time() > b.backup_dir.backup_time() { + a + } else { + b + } }) + .to_owned(); + + let notes_path = datastore.group_notes_path(ns, group.as_ref()); + let comment = file_read_firstline(notes_path).ok(); + + let item = GroupListItem { + backup: group.into(), + last_backup: last_backup.backup_dir.backup_time(), + owner: Some(owner), + backup_count, + files: last_backup.files, + comment, + }; + + Some(item) } #[api( -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel