From 2aaf3ef1e5b77101ba7e7d1832d76ff23349814b Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Tue, 15 Nov 2022 09:08:09 +0100 Subject: [PATCH] file-restore: move various formats to inline-string macros Signed-off-by: Thomas Lamprecht --- proxmox-file-restore/src/block_driver.rs | 6 +++--- proxmox-file-restore/src/block_driver_qemu.rs | 11 +++++------ proxmox-file-restore/src/main.rs | 6 +++--- proxmox-file-restore/src/qemu_helper.rs | 8 ++++---- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/proxmox-file-restore/src/block_driver.rs b/proxmox-file-restore/src/block_driver.rs index 01cc4e18..fa954832 100644 --- a/proxmox-file-restore/src/block_driver.rs +++ b/proxmox-file-restore/src/block_driver.rs @@ -163,9 +163,9 @@ pub async fn status(driver: Option, param: Value) -> Result<(), } Err(err) => { if text { - eprintln!("error getting status from driver '{}' - {}", drv_name, err); + eprintln!("error getting status from driver '{drv_name}' - {err}"); } else { - ret[drv_name] = json!({ "error": format!("{}", err) }); + ret[drv_name] = json!({ "error": format!("{err}") }); } } } @@ -197,7 +197,7 @@ pub async fn stop(name: String) -> Result<(), Error> { } } - bail!("no mapping with name '{}' found", name); + bail!("no mapping with name '{name}' found"); } /// Autocompletion handler for block mappings diff --git a/proxmox-file-restore/src/block_driver_qemu.rs b/proxmox-file-restore/src/block_driver_qemu.rs index f73e5938..ecc39261 100644 --- a/proxmox-file-restore/src/block_driver_qemu.rs +++ b/proxmox-file-restore/src/block_driver_qemu.rs @@ -84,9 +84,9 @@ impl VMStateMap { fn make_name(repo: &BackupRepository, ns: &BackupNamespace, snap: &BackupDir) -> String { let full = if ns.is_root() { - format!("qemu_{}/{}", repo, snap) + format!("qemu_{repo}/{snap}") } else { - format!("qemu_{}:{}/{}", repo, ns, snap) + format!("qemu_{repo}:{ns}/{snap}") }; proxmox_sys::systemd::escape_unit(&full, false) } @@ -321,13 +321,12 @@ impl BlockRestoreDriver for QemuBlockDriver { } } None => { - let err = - format!("invalid JSON received from /status call: {}", status); + let err = format!("invalid JSON received from /status call: {status}"); extra["error"] = json!(err); } }, Err(err) => { - let err = format!("error during /status API call: {}", err); + let err = format!("error during /status API call: {err}"); extra["error"] = json!(err); } } @@ -363,7 +362,7 @@ impl BlockRestoreDriver for QemuBlockDriver { if map_mod { map.write()?; } - bail!("VM with name '{}' not found", name); + bail!("VM with name '{name}' not found"); } } Ok(()) diff --git a/proxmox-file-restore/src/main.rs b/proxmox-file-restore/src/main.rs index 2f941e5a..7f35bd5d 100644 --- a/proxmox-file-restore/src/main.rs +++ b/proxmox-file-restore/src/main.rs @@ -489,8 +489,8 @@ async fn extract( // we extracted a .pxarexclude-cli file auto-generated by the VM when encoding the // archive, this file is of no use for the user, so try to remove it target.push(".pxarexclude-cli"); - std::fs::remove_file(target).map_err(|e| { - format_err!("unable to remove temporary .pxarexclude-cli file - {}", e) + std::fs::remove_file(target).map_err(|err| { + format_err!("unable to remove temporary .pxarexclude-cli file - {err}") })?; } else { let mut reader = @@ -499,7 +499,7 @@ async fn extract( } } _ => { - bail!("cannot extract '{}'", orig_path); + bail!("cannot extract '{orig_path}'"); } } diff --git a/proxmox-file-restore/src/qemu_helper.rs b/proxmox-file-restore/src/qemu_helper.rs index 7956f241..c49f80d9 100644 --- a/proxmox-file-restore/src/qemu_helper.rs +++ b/proxmox-file-restore/src/qemu_helper.rs @@ -369,7 +369,7 @@ pub async fn start_vm( let mut pidstr = String::new(); pid_file.read_to_string(&mut pidstr)?; pid = pidstr.trim_end().parse().map_err(|err| { - format_err!("cannot parse PID returned by QEMU ('{}'): {}", &pidstr, err) + format_err!("cannot parse PID returned by QEMU ('{pidstr}'): {err}") })?; break; } else { @@ -377,14 +377,14 @@ pub async fn start_vm( if out.contains("unable to set guest cid: Address already in use") { attempts += 1; if attempts >= MAX_CID_TRIES { - bail!("CID '{}' in use, but max attempts reached, aborting", cid); + bail!("CID '{cid}' in use, but max attempts reached, aborting"); } // CID in use, try next higher one - log::info!("CID '{}' in use by other VM, attempting next one", cid); + log::info!("CID '{cid}' in use by other VM, attempting next one"); // skip special-meaning low values cid = cid.wrapping_add(1).max(10); } else { - log::error!("{}", out); + log::error!("{out}"); bail!("Starting VM failed. See output above for more information."); } }