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
2022-05-05 17:17:02 +02:00
parent 08aa5fe7aa
commit 15a9272495
2 changed files with 52 additions and 21 deletions

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)? {