datastore: move last_backup from BackupInfo to BackupGroup

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2022-04-20 09:55:48 +02:00
parent fe94c9962e
commit c4b2d26cdb
2 changed files with 16 additions and 15 deletions

View File

@ -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<Option<BackupInfo>, 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<Option<i64>, 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<Option<BackupInfo>, 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<BackupInfo>, ascendending: bool) {
if ascendending {
// oldest first