debug: recover: allow overriding output-path

including to STDOUT.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Hannes Laimer <h.laimer@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2022-05-23 16:11:35 +02:00 committed by Thomas Lamprecht
parent b11693b2f7
commit 9f8aa8c5e2
1 changed files with 16 additions and 3 deletions

View File

@ -51,6 +51,11 @@ use pbs_tools::crypt_config::CryptConfig;
optional: true, optional: true,
default: false, 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, skip_crc: bool,
ignore_missing_chunks: bool, ignore_missing_chunks: bool,
ignore_corrupt_chunks: bool, ignore_corrupt_chunks: bool,
output_path: Option<String>,
_param: Value, _param: Value,
) -> Result<(), Error> { ) -> Result<(), Error> {
let file_path = Path::new(&file); let file_path = Path::new(&file);
@ -92,9 +98,16 @@ fn recover_index(
None None
}; };
let output_filename = file_path.file_stem().unwrap().to_str().unwrap(); let output_path = output_path.unwrap_or_else(|| {
let output_path = Path::new(output_filename); let filename = file_path.file_stem().unwrap().to_str().unwrap();
let mut output_file = File::create(output_path) 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))?; .map_err(|e| format_err!("could not create output file - {}", e))?;
let mut data = Vec::with_capacity(4 * 1024 * 1024); let mut data = Vec::with_capacity(4 * 1024 * 1024);