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 <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2020-02-27 14:22:04 +01:00 committed by Dietmar Maurer
parent 351b913d1e
commit 8e464141cf
1 changed files with 26 additions and 3 deletions

View File

@ -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<bool>) -> 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(())
})