From 8e464141cf06b4bc70d467c9e4e48b76d1b3cde0 Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Thu, 27 Feb 2020 14:22:04 +0100 Subject: [PATCH] catalog: shell: Improve list-selected command. 'list-selected' now shows the filenames matching the patterns for a restore instead of the patterns themselfs. The patterns can be displayed by passing the '--pattern' flag. Signed-off-by: Christian Ebner --- src/backup/catalog_shell.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/backup/catalog_shell.rs b/src/backup/catalog_shell.rs index a59446a3..645d7d4d 100644 --- a/src/backup/catalog_shell.rs +++ b/src/backup/catalog_shell.rs @@ -494,12 +494,35 @@ fn restore_selected_command(target: String) -> Result<(), Error> { }) } -#[api( input: { properties: {} })] +#[api( + input: { + properties: { + pattern: { + type: Boolean, + description: "List match patterns instead of the matching files.", + optional: true, + } + } + } +)] /// List entries currently selected for restore. -fn list_selected_command() -> Result<(), Error> { +fn list_selected_command(pattern: Option) -> Result<(), Error> { Context::with(|ctx| { let mut out = std::io::stdout(); - out.write_all(&MatchPattern::to_bytes(ctx.selected.as_slice()))?; + if let Some(true) = pattern { + out.write_all(&MatchPattern::to_bytes(ctx.selected.as_slice()))?; + } else { + let mut slices = Vec::with_capacity(ctx.selected.len()); + for pattern in &ctx.selected { + slices.push(pattern.as_slice()); + } + let mut dir_stack = ctx.root.clone(); + ctx.catalog.find( + &mut dir_stack, + &slices, + &Box::new(|path: &[DirEntry]| println!("{:?}", Context::generate_cstring(path).unwrap())) + )?; + } out.flush()?; Ok(()) })