From c4b2d26cdb8ff40ddb889f02008dca215fbb0d3a Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 20 Apr 2022 09:55:48 +0200 Subject: [PATCH] datastore: move last_backup from BackupInfo to BackupGroup Signed-off-by: Wolfgang Bumiller --- pbs-datastore/src/backup_info.rs | 26 +++++++++++++------------- src/api2/backup/mod.rs | 5 +++-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs index c5f4b72d..d6c67b73 100644 --- a/pbs-datastore/src/backup_info.rs +++ b/pbs-datastore/src/backup_info.rs @@ -103,6 +103,19 @@ impl BackupGroup { Ok(list) } + /// Finds the latest backup inside a backup group + pub fn last_backup( + &self, + base_path: &Path, + only_finished: bool, + ) -> Result, Error> { + let backups = self.list_backups(base_path)?; + Ok(backups + .into_iter() + .filter(|item| !only_finished || item.is_finished()) + .max_by_key(|item| item.backup_dir.backup_time())) + } + pub fn last_successful_backup(&self, base_path: &Path) -> Result, Error> { let mut last = None; @@ -363,19 +376,6 @@ impl BackupInfo { }) } - /// Finds the latest backup inside a backup group - pub fn last_backup( - base_path: &Path, - group: &BackupGroup, - only_finished: bool, - ) -> Result, Error> { - let backups = group.list_backups(base_path)?; - Ok(backups - .into_iter() - .filter(|item| !only_finished || item.is_finished()) - .max_by_key(|item| item.backup_dir.backup_time())) - } - pub fn sort_list(list: &mut Vec, ascendending: bool) { if ascendending { // oldest first diff --git a/src/api2/backup/mod.rs b/src/api2/backup/mod.rs index febe79d1..c01259d1 100644 --- a/src/api2/backup/mod.rs +++ b/src/api2/backup/mod.rs @@ -21,7 +21,7 @@ use pbs_api_types::{ DATASTORE_SCHEMA, PRIV_DATASTORE_BACKUP, }; use pbs_config::CachedUserInfo; -use pbs_datastore::backup_info::{BackupDir, BackupGroup, BackupInfo}; +use pbs_datastore::backup_info::{BackupDir, BackupGroup}; use pbs_datastore::index::IndexFile; use pbs_datastore::manifest::{archive_type, ArchiveType}; use pbs_datastore::{DataStore, PROXMOX_BACKUP_PROTOCOL_ID_V1}; @@ -134,7 +134,8 @@ fn upgrade_to_backup_protocol( } let last_backup = { - let info = BackupInfo::last_backup(&datastore.base_path(), &backup_group, true) + let info = backup_group + .last_backup(&datastore.base_path(), true) .unwrap_or(None); if let Some(info) = info { let (manifest, _) = datastore.load_manifest(&info.backup_dir)?;