diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 1309ab40..875e3d4a 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -166,66 +166,66 @@ pub fn list_groups( let datastore = DataStore::lookup_datastore(&store, Some(Operation::Read))?; let list_all = (user_privs & PRIV_DATASTORE_AUDIT) != 0; - let backup_groups = BackupInfo::list_backup_groups(&datastore.base_path())?; - - let group_info = backup_groups - .into_iter() - .fold(Vec::new(), |mut group_info, group| { - let owner = match datastore.get_owner(&group) { - Ok(auth_id) => auth_id, - Err(err) => { - eprintln!( - "Failed to get owner of group '{}/{}' - {}", - &store, group, err - ); - return group_info; - } - }; - if !list_all && check_backup_owner(&owner, &auth_id).is_err() { - return group_info; - } - - let snapshots = match group.list_backups(&datastore.base_path()) { - Ok(snapshots) => snapshots, - Err(_) => { - return group_info; - } - }; - - let backup_count: u64 = snapshots.len() as u64; - if backup_count == 0 { - return group_info; - } - - let last_backup = snapshots - .iter() - .fold(&snapshots[0], |last, curr| { - if curr.is_finished() - && curr.backup_dir.backup_time() > last.backup_dir.backup_time() - { - curr - } else { - last + let group_info = + datastore + .list_backup_groups()? + .into_iter() + .fold(Vec::new(), |mut group_info, group| { + let owner = match datastore.get_owner(&group) { + Ok(auth_id) => auth_id, + Err(err) => { + eprintln!( + "Failed to get owner of group '{}/{}' - {}", + &store, group, err + ); + return group_info; } - }) - .to_owned(); + }; + if !list_all && check_backup_owner(&owner, &auth_id).is_err() { + return group_info; + } - let note_path = get_group_note_path(&datastore, &group); - let comment = file_read_firstline(¬e_path).ok(); + let snapshots = match group.list_backups(&datastore.base_path()) { + Ok(snapshots) => snapshots, + Err(_) => { + return group_info; + } + }; - group_info.push(GroupListItem { - backup_type: group.backup_type().to_string(), - backup_id: group.backup_id().to_string(), - last_backup: last_backup.backup_dir.backup_time(), - owner: Some(owner), - backup_count, - files: last_backup.files, - comment, + let backup_count: u64 = snapshots.len() as u64; + if backup_count == 0 { + return group_info; + } + + let last_backup = snapshots + .iter() + .fold(&snapshots[0], |last, curr| { + if curr.is_finished() + && curr.backup_dir.backup_time() > last.backup_dir.backup_time() + { + curr + } else { + last + } + }) + .to_owned(); + + let note_path = get_group_note_path(&datastore, &group); + let comment = file_read_firstline(¬e_path).ok(); + + group_info.push(GroupListItem { + backup_type: group.backup_type().to_string(), + backup_id: group.backup_id().to_string(), + last_backup: last_backup.backup_dir.backup_time(), + owner: Some(owner), + backup_count, + files: last_backup.files, + comment, + }); + + group_info }); - group_info - }); - Ok(group_info) } @@ -417,30 +417,30 @@ pub fn list_snapshots( let datastore = DataStore::lookup_datastore(&store, Some(Operation::Read))?; - let base_path = datastore.base_path(); - let groups = match (backup_type, backup_id) { (Some(backup_type), Some(backup_id)) => { let mut groups = Vec::with_capacity(1); groups.push(BackupGroup::new(backup_type, backup_id)); groups } - (Some(backup_type), None) => BackupInfo::list_backup_groups(&base_path)? + (Some(backup_type), None) => datastore + .list_backup_groups()? .into_iter() .filter(|group| group.backup_type() == backup_type) .collect(), - (None, Some(backup_id)) => BackupInfo::list_backup_groups(&base_path)? + (None, Some(backup_id)) => datastore + .list_backup_groups()? .into_iter() .filter(|group| group.backup_id() == backup_id) .collect(), - _ => BackupInfo::list_backup_groups(&base_path)?, + _ => datastore.list_backup_groups()?, }; let info_to_snapshot_list_item = |group: &BackupGroup, owner, info: BackupInfo| { let backup_type = group.backup_type().to_string(); let backup_id = group.backup_id().to_string(); let backup_time = info.backup_dir.backup_time(); - let protected = info.backup_dir.is_protected(base_path.clone()); + let protected = info.backup_dir.is_protected(datastore.base_path()); match get_all_snapshot_files(&datastore, &info) { Ok((manifest, files)) => { @@ -540,11 +540,9 @@ pub fn list_snapshots( } fn get_snapshots_count(store: &DataStore, filter_owner: Option<&Authid>) -> Result { - let base_path = store.base_path(); - let groups = BackupInfo::list_backup_groups(&base_path)?; - - groups - .iter() + store + .list_backup_groups()? + .into_iter() .filter(|group| { let owner = match store.get_owner(group) { Ok(owner) => owner, @@ -565,7 +563,7 @@ fn get_snapshots_count(store: &DataStore, filter_owner: Option<&Authid>) -> Resu } }) .try_fold(Counts::default(), |mut counts, group| { - let snapshot_count = group.list_backups(&base_path)?.len() as u64; + let snapshot_count = group.list_backups(&store.base_path())?.len() as u64; // only include groups with snapshots (avoid confusing users // by counting/displaying emtpy groups) diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs index d4d390e3..e2c0e8ad 100644 --- a/src/api2/tape/backup.rs +++ b/src/api2/tape/backup.rs @@ -408,7 +408,7 @@ fn backup_worker( let mut pool_writer = PoolWriter::new(pool, &setup.drive, worker, email, force_media_set)?; - let mut group_list = BackupInfo::list_backup_groups(&datastore.base_path())?; + let mut group_list = datastore.list_backup_groups()?; group_list.sort_unstable(); diff --git a/src/backup/verify.rs b/src/backup/verify.rs index 74f8b23c..6a10653e 100644 --- a/src/backup/verify.rs +++ b/src/backup/verify.rs @@ -537,7 +537,7 @@ pub fn verify_all_backups( } }; - let mut list = match BackupInfo::list_backup_groups(&verify_worker.datastore.base_path()) { + let mut list = match verify_worker.datastore.list_backup_groups() { Ok(list) => list .into_iter() .filter(|group| !(group.backup_type() == "host" && group.backup_id() == "benchmark")) diff --git a/src/server/prune_job.rs b/src/server/prune_job.rs index 0ff420c6..94603a2b 100644 --- a/src/server/prune_job.rs +++ b/src/server/prune_job.rs @@ -6,7 +6,6 @@ use proxmox_sys::{task_log, task_warn}; use pbs_api_types::{Authid, Operation, PruneOptions, PRIV_DATASTORE_MODIFY}; use pbs_config::CachedUserInfo; -use pbs_datastore::backup_info::BackupInfo; use pbs_datastore::prune::compute_prune_info; use pbs_datastore::DataStore; use proxmox_rest_server::WorkerTask; @@ -43,11 +42,8 @@ pub fn prune_datastore( let privs = user_info.lookup_privs(&auth_id, &["datastore", store]); let has_privs = privs & PRIV_DATASTORE_MODIFY != 0; - let base_path = datastore.base_path(); - - let groups = BackupInfo::list_backup_groups(&base_path)?; - for group in groups { - let list = group.list_backups(&base_path)?; + for group in datastore.list_backup_groups()? { + let list = group.list_backups(&datastore.base_path())?; if !has_privs && !datastore.owns_backup(&group, &auth_id)? { continue; diff --git a/src/server/pull.rs b/src/server/pull.rs index 3b6f912d..6437ee21 100644 --- a/src/server/pull.rs +++ b/src/server/pull.rs @@ -28,7 +28,7 @@ use pbs_datastore::index::IndexFile; use pbs_datastore::manifest::{ archive_type, ArchiveType, BackupManifest, FileInfo, CLIENT_LOG_BLOB_NAME, MANIFEST_BLOB_NAME, }; -use pbs_datastore::{BackupDir, BackupGroup, BackupInfo, DataStore, StoreProgress}; +use pbs_datastore::{BackupDir, BackupGroup, DataStore, StoreProgress}; use pbs_tools::sha::sha256; use proxmox_rest_server::WorkerTask; @@ -797,8 +797,7 @@ pub async fn pull_store( if params.remove_vanished { let result: Result<(), Error> = proxmox_lang::try_block!({ - let local_groups = BackupInfo::list_backup_groups(¶ms.store.base_path())?; - for local_group in local_groups { + for local_group in params.store.list_backup_groups()? { if new_groups.contains(&local_group) { continue; }