api: tape restore: refactor some code parts shorter

not wanting to play code golf here, but bloat in code makes it often
also harder to read, so try to reduce some of that without making it
to terse.

No semantic change intended.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-06-05 10:42:46 +02:00
parent a40ffb92ac
commit 20a04cf07c
1 changed files with 16 additions and 29 deletions

View File

@ -476,26 +476,19 @@ fn restore_full_worker(
} }
let used_datastores = store_map.used_datastores(); let used_datastores = store_map.used_datastores();
task_log!( let datastore_list = used_datastores
worker, .values()
"Datastore(s): {}", .map(|(t, _)| String::from(t.name()))
used_datastores .collect::<Vec<String>>()
.values() .join(", ");
.map(|(t, _)| String::from(t.name())) task_log!(worker, "Datastore(s): {datastore_list}",);
.collect::<Vec<String>>() task_log!(worker, "Drive: {drive_name}");
.join(", "), let required_media = media_id_list
); .iter()
.map(|media_id| media_id.label.label_text.as_str())
task_log!(worker, "Drive: {}", drive_name); .collect::<Vec<&str>>()
task_log!( .join(";");
worker, task_log!(worker, "Required media list: {required_media}",);
"Required media list: {}",
media_id_list
.iter()
.map(|media_id| media_id.label.label_text.as_str())
.collect::<Vec<&str>>()
.join(";")
);
let mut datastore_locks = Vec::new(); let mut datastore_locks = Vec::new();
for (target, _) in used_datastores.values() { for (target, _) in used_datastores.values() {
@ -549,12 +542,8 @@ fn check_snapshot_restorable(
(datastore, namespaces) (datastore, namespaces)
} else { } else {
match store_map.get_targets(store, ns) { match store_map.get_targets(store, ns) {
Some((ds, Some(ns))) => { Some((_, Some(ns))) if ns.is_empty() => return Ok(false),
if ns.is_empty() { Some((datastore, Some(ns))) => (datastore, ns),
return Ok(false);
}
(ds, ns)
}
Some((_, None)) => return Ok(false), Some((_, None)) => return Ok(false),
None => return Ok(false), None => return Ok(false),
} }
@ -830,9 +819,7 @@ fn restore_list_worker(
format_err!("unexpected source datastore: {}", source_datastore) format_err!("unexpected source datastore: {}", source_datastore)
})?; })?;
let namespaces = target_ns.unwrap_or_else(|| vec![source_ns.clone()]); for ns in target_ns.unwrap_or_else(|| vec![source_ns.clone()]) {
for ns in namespaces {
if let Err(err) = proxmox_lang::try_block!({ if let Err(err) = proxmox_lang::try_block!({
check_and_create_namespaces( check_and_create_namespaces(
&user_info, &user_info,