datastore: add max-depth to recursive namespace iter

on depth == 0 we only yield the anchor ns, this simplifies usage in
the API as for, e.g. list-snapthos the depth == 0 means only the
snapshots from the passed namespace, nothing below.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht committed 2022-05-12 09:33:50 +02:00
1 parent 08aa5fe7aa
commit 15a9272495
2 files changed
+52 -21

No files matched your search

+10 -2
View File
@@ -7,12 +7,20 @@ use pbs_datastore::DataStore;
fn run() -> Result<(), Error> {
let base: PathBuf = match std::env::args().skip(1).next() {
Some(path) => path.into(),
None => bail!("no path passed"),
None => bail!("no path passed!\n\nusage: ls-snapshots <path> [<max-depth>]"),
};
let max_depth: Option<usize> = match std::env::args().skip(2).next() {
Some(depth) => match depth.parse::<usize>() {
Ok(depth) if depth < 8 => Some(depth),
Ok(_) => bail!("max-depth must be < 8"),
Err(err) => bail!("couldn't parse max-depth from {depth} - {err}"),
},
None => None,
};
let store = unsafe { DataStore::open_path("", &base, None)? };
for ns in store.recursive_iter_backup_ns_ok(Default::default())? {
for ns in store.recursive_iter_backup_ns_ok(Default::default(), max_depth)? {
println!("found namespace store:/{}", ns);
for group in store.iter_backup_groups(ns)? {