datastore: add helper to get a iterator for backup groups

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-04-15 12:15:54 +02:00
parent de015ce7e1
commit 7b125de3e1
1 changed files with 26 additions and 0 deletions

View File

@ -552,7 +552,33 @@ impl DataStore {
}
}
/// Get a streaming iter over top-level backup groups of a datatstore
///
/// The iterated item is still a Result that can contain errors from rather unexptected FS or
/// parsing errors.
pub fn iter_backup_groups(&self) -> Result<ListGroups, Error> {
ListGroups::new(self.base_path())
}
/// Get a streaming iter over top-level backup groups of a datatstore, filtered by Ok results
///
/// The iterated item's result is already unwrapped, if it contained an error it will be
/// logged. Can be useful in iterator chain commands
pub fn iter_backup_groups_ok(&self) -> Result<impl Iterator<Item = BackupGroup> + '_, Error> {
Ok(
ListGroups::new(self.base_path())?.filter_map(move |group| match group {
Ok(group) => Some(group),
Err(err) => {
log::error!("list groups error on datastore {} - {}", self.name(), err);
None
}
}),
)
}
/// Get a in-memory vector for all top-level backup groups of a datatstore
///
/// NOTE: using the iterator directly is most often more efficient w.r.t. memory usage
pub fn list_backup_groups(&self) -> Result<Vec<BackupGroup>, Error> {
ListGroups::new(self.base_path())?.collect()
}