From 950fba5a47218efb1cd4c40f0b9868e1eed21f42 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Thu, 15 Jun 2023 18:08:40 +0200 Subject: [PATCH] file-restore: factor out detecting debug mode to avoid that the detection logic gets out of sync Signed-off-by: Thomas Lamprecht --- proxmox-file-restore/src/main.rs | 7 +++---- proxmox-file-restore/src/qemu_helper.rs | 10 +++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/proxmox-file-restore/src/main.rs b/proxmox-file-restore/src/main.rs index 74ef1979..9c74a476 100644 --- a/proxmox-file-restore/src/main.rs +++ b/proxmox-file-restore/src/main.rs @@ -585,11 +585,10 @@ where } fn main() { - let loglevel = match std::env::var("PBS_QEMU_DEBUG") { - Ok(val) if !val.is_empty() => "debug", - _ => "info" + let loglevel = match qemu_helper::debug_mode() { + true => "debug", + false => "info", }; - init_cli_logger("PBS_LOG", loglevel); let list_cmd_def = CliCommand::new(&API_METHOD_LIST) diff --git a/proxmox-file-restore/src/qemu_helper.rs b/proxmox-file-restore/src/qemu_helper.rs index 0219a310..17784c28 100644 --- a/proxmox-file-restore/src/qemu_helper.rs +++ b/proxmox-file-restore/src/qemu_helper.rs @@ -194,6 +194,10 @@ pub(crate) async fn hotplug_memory(cid: i32, dimm_mb: usize) -> Result<(), Error Ok(()) } +pub fn debug_mode() -> bool { + std::env::var("PBS_QEMU_DEBUG").map(|s| !s.is_empty()).unwrap_or(false) +} + pub async fn start_vm( // u16 so we can do wrapping_add without going too high mut cid: u16, @@ -205,11 +209,7 @@ pub async fn start_vm( bail!("environment variable PBS_PASSWORD has to be set for QEMU VM restore"); } - let debug = if let Ok(val) = std::env::var("PBS_QEMU_DEBUG") { - !val.is_empty() - } else { - false - }; + let debug = debug_mode(); validate_img_existance(debug)?;