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,30 +631,28 @@ 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),
let snapshot = print_ns_and_snapshot(&ns, &dir); _ => continue,
match check_snapshot_restorable( };
&worker, let snapshot = print_ns_and_snapshot(&ns, &dir);
&store_map, match check_snapshot_restorable(
store, &worker,
&snapshot, &store_map,
&ns, store,
&dir, &snapshot,
false, &ns,
&user_info, &dir,
auth_id, false,
restore_owner, &user_info,
) { auth_id,
Ok(true) => { restore_owner,
restorable.push((store.to_string(), snapshot.to_string(), ns, dir)) ) {
} Ok(true) => 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}");
skipped.push(format!("{store}:{snapshot}")); skipped.push(format!("{store}:{snapshot}"));
}
}
} }
} }
} }