api: tape restore: code cleanup to reduce indentation level

No semantic change intended. IMO the interface of "both a datastore
and NS mapping must be present" is still a bit weird, at least in how
its used here to decide what to skip and what not, maybe we can
implement this in a more clear way (or maybe I'm just overlooking
something that makes it clearer as is).

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-06-07 14:12:00 +02:00
parent 74cad4a8bd
commit 72b550a836

View File

@ -202,6 +202,11 @@ impl DataStoreMap {
self.target_store(source_datastore) self.target_store(source_datastore)
.map(|store| (store, self.target_ns(source_datastore, source_ns))) .map(|store| (store, self.target_ns(source_datastore, source_ns)))
} }
/// Returns true if there's both a datastore and namespace mapping from a source datastore/ns
fn has_full_mapping(&self, datastore: &str, ns: &BackupNamespace) -> bool {
self.target_store(datastore).is_some() && self.target_ns(datastore, ns).is_some()
}
} }
fn check_datastore_privs( fn check_datastore_privs(
@ -626,8 +631,10 @@ fn restore_list_worker(
let mut restorable = Vec::new(); let mut restorable = Vec::new();
// restore source namespaces // restore source namespaces
for (store, snapshot) in catalog.list_snapshots() { for (store, snapshot) in catalog.list_snapshots() {
if let Ok((ns, dir)) = parse_ns_and_snapshot(&snapshot) { let (ns, dir) = match parse_ns_and_snapshot(&snapshot) {
if let Some((_, Some(_))) = store_map.get_targets(store, &ns) { Ok((ns, dir)) if store_map.has_full_mapping(store, &ns) => (ns, dir),
_ => continue,
};
let snapshot = print_ns_and_snapshot(&ns, &dir); let snapshot = print_ns_and_snapshot(&ns, &dir);
match check_snapshot_restorable( match check_snapshot_restorable(
&worker, &worker,
@ -641,9 +648,7 @@ fn restore_list_worker(
auth_id, auth_id,
restore_owner, restore_owner,
) { ) {
Ok(true) => { Ok(true) => restorable.push((store.to_string(), snapshot.to_string(), ns, dir)),
restorable.push((store.to_string(), snapshot.to_string(), ns, dir))
}
Ok(false) => {} Ok(false) => {}
Err(err) => { Err(err) => {
task_warn!(worker, "{err}"); task_warn!(worker, "{err}");
@ -651,8 +656,6 @@ fn restore_list_worker(
} }
} }
} }
}
}
restorable restorable
} else { } else {
snapshots snapshots