From 9f8aa8c5e2cd9c0979292faecabae30add015bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Mon, 23 May 2022 16:11:35 +0200 Subject: [PATCH] debug: recover: allow overriding output-path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit including to STDOUT. Signed-off-by: Fabian Grünbichler Tested-by: Hannes Laimer --- src/bin/proxmox_backup_debug/recover.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/bin/proxmox_backup_debug/recover.rs b/src/bin/proxmox_backup_debug/recover.rs index 9c4aed3d..23366b86 100644 --- a/src/bin/proxmox_backup_debug/recover.rs +++ b/src/bin/proxmox_backup_debug/recover.rs @@ -51,6 +51,11 @@ use pbs_tools::crypt_config::CryptConfig; optional: true, default: false, }, + "output-path": { + type: String, + description: "Output file path, defaults to `file` without extension, '-' means STDOUT.", + optional: true, + }, } } )] @@ -63,6 +68,7 @@ fn recover_index( skip_crc: bool, ignore_missing_chunks: bool, ignore_corrupt_chunks: bool, + output_path: Option, _param: Value, ) -> Result<(), Error> { let file_path = Path::new(&file); @@ -92,9 +98,16 @@ fn recover_index( None }; - let output_filename = file_path.file_stem().unwrap().to_str().unwrap(); - let output_path = Path::new(output_filename); - let mut output_file = File::create(output_path) + let output_path = output_path.unwrap_or_else(|| { + let filename = file_path.file_stem().unwrap().to_str().unwrap(); + filename.to_string() + }); + + let output_path = match output_path.as_str() { + "-" => None, + path => Some(path), + }; + let mut output_file = crate::outfile_or_stdout(output_path) .map_err(|e| format_err!("could not create output file - {}", e))?; let mut data = Vec::with_capacity(4 * 1024 * 1024);