From cd1bb88f20fd32d0fafc098487b83439123a7124 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 4 Dec 2015 23:19:18 +0100 Subject: [PATCH] Rework remove_command() --- src/module/bm/commands.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/module/bm/commands.rs b/src/module/bm/commands.rs index 84efcf21..59f507f3 100644 --- a/src/module/bm/commands.rs +++ b/src/module/bm/commands.rs @@ -60,22 +60,24 @@ pub fn remove_command(module: &Module, env: CommandEnv) -> CommandResult { debug!("Remove by id: {}", id); let parser = Parser::new(JsonHeaderParser::new(None)); - env.bk.get_file_by_id(module, &id.into(), &parser).map(|file| { - debug!("Remove file : {:?}", file); + let file = env.bk + .get_file_by_id(module, &id.into(), &parser) + .unwrap_or({ + info!("No files found"); + return Ok(()) + }); - if let Err(e) = env.bk.remove_file(module, file, checked) { - debug!("Remove failed"); - let mut err = ModuleError::new("Removing file failed"); - err.caused_by = Some(Box::new(e)); - Err(err) - } else { - info!("Remove worked"); - Ok(()) - } - }).unwrap_or({ - info!("No files found"); + debug!("Remove file: {:?}", file); + + if let Err(e) = env.bk.remove_file(module, file, checked) { + debug!("Remove failed"); + let mut err = ModuleError::new("Removing file failed"); + err.caused_by = Some(Box::new(e)); + Err(err) + } else { + info!("Remove worked"); Ok(()) - }) + } } else { debug!("Remove more than one file");