From 7b125de3e18e8c946ff18e71e782dfb5b955a7ec Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 15 Apr 2022 12:15:54 +0200 Subject: [PATCH] datastore: add helper to get a iterator for backup groups Signed-off-by: Thomas Lamprecht --- pbs-datastore/src/datastore.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index 6314481d..0bd1fa34 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -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::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 + '_, 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, Error> { ListGroups::new(self.base_path())?.collect() }