From c90dbb5c7be5b336185e1605dd33329c540ce6e3 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 15 Apr 2022 09:03:13 +0200 Subject: [PATCH] datastore: move list_backup_groups into Datastore impl Having that as static method in BackupInfo makes zero sense and just complicates call sites, which need to extract the base_path from the store manually upfront. Mark old fn as deprecated so that we can do the move in a separate step. It's also planned to add an Iterator impl for this to allow more efficient usage in the future. Signed-off-by: Thomas Lamprecht --- pbs-datastore/src/backup_info.rs | 1 + pbs-datastore/src/datastore.rs | 34 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs index 1902e135..522bc059 100644 --- a/pbs-datastore/src/backup_info.rs +++ b/pbs-datastore/src/backup_info.rs @@ -369,6 +369,7 @@ impl BackupInfo { Ok(files) } + #[deprecated = "move to datastore"] pub fn list_backup_groups(base_path: &Path) -> Result, Error> { let mut list = Vec::new(); diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index 1d389d58..8a1c6fa0 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -19,7 +19,7 @@ use proxmox_sys::{task_log, task_warn}; use pbs_api_types::{ Authid, ChunkOrder, DataStoreConfig, DatastoreTuning, GarbageCollectionStatus, HumanByte, - Operation, UPID, + Operation, BACKUP_ID_REGEX, BACKUP_TYPE_REGEX, UPID, }; use pbs_config::{open_backup_lockfile, BackupLockGuard, ConfigVersionCache}; @@ -552,6 +552,38 @@ impl DataStore { } } + /// Get a in-memory vector for all top-level backup groups of a datatstore + pub fn list_backup_groups(&self) -> Result, Error> { + let mut list = Vec::new(); + + proxmox_sys::fs::scandir( + libc::AT_FDCWD, + &self.base_path(), + &BACKUP_TYPE_REGEX, + |l0_fd, backup_type, file_type| { + if file_type != nix::dir::Type::Directory { + return Ok(()); + } + proxmox_sys::fs::scandir( + l0_fd, + backup_type, + &BACKUP_ID_REGEX, + |_, backup_id, file_type| { + if file_type != nix::dir::Type::Directory { + return Ok(()); + } + + list.push(BackupGroup::new(backup_type, backup_id)); + + Ok(()) + }, + ) + }, + )?; + + Ok(list) + } + pub fn list_images(&self) -> Result, Error> { let base = self.base_path();