Implement remove_command()
This commit is contained in:
parent
484b1fb865
commit
c81d0bf0a8
1 changed files with 45 additions and 19 deletions
|
@ -1,5 +1,5 @@
|
||||||
use runtime::Runtime;
|
use runtime::Runtime;
|
||||||
use storage::backend::StorageBackend;
|
use storage::backend::{StorageBackendError, StorageBackend};
|
||||||
|
|
||||||
use module::Module;
|
use module::Module;
|
||||||
use module::ModuleError;
|
use module::ModuleError;
|
||||||
|
@ -45,28 +45,54 @@ pub fn list_command(module: &Module, env: CommandEnv) -> CommandResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_command(module: &Module, env: CommandEnv) -> CommandResult {
|
pub fn remove_command(module: &Module, env: CommandEnv) -> CommandResult {
|
||||||
let tags = get_tags(env.rt, env.matches);
|
if let Some(id) = get_id(env.rt, env.matches) {
|
||||||
let matcher = get_matcher(env.rt, env.matches);
|
debug!("Remove by id: {}", id);
|
||||||
let id = get_id(env.rt, env.matches);
|
|
||||||
|
|
||||||
match id {
|
let parser = Parser::new(JsonHeaderParser::new(None));
|
||||||
Some(idstr) => {
|
let file = env.bk.get_file_by_id(module, &id, &parser).unwrap();
|
||||||
info!("Removing urls with id '{}'", idstr);
|
debug!("Remove file : {:?}", file);
|
||||||
}
|
|
||||||
None => {
|
|
||||||
match matcher {
|
|
||||||
Some(reg) => {
|
|
||||||
info!("Removing urls with matcher '{}' and with tags {:?}",
|
|
||||||
reg.as_str(), tags);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
info!("Listing urls with tags {:?}", tags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if let Err(e) = env.bk.remove_file(module, file) {
|
||||||
|
debug!("Remove failed");
|
||||||
|
let mut err = ModuleError::new("Removing file failed");
|
||||||
|
err.caused_by = Some(Box::new(e));
|
||||||
|
Err(err)
|
||||||
|
} else {
|
||||||
|
debug!("Remove worked");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debug!("Remove more than one file");
|
||||||
|
|
||||||
|
let files = get_filtered_files_from_backend(module, &env);
|
||||||
|
let nfiles = files.len();
|
||||||
|
info!("Removing {} Files", nfiles);
|
||||||
|
|
||||||
|
let errs = files.map(|file| {
|
||||||
|
debug!("Remove file: {:?}", file);
|
||||||
|
env.bk.remove_file(module, file)
|
||||||
|
})
|
||||||
|
.filter(|e| e.is_err())
|
||||||
|
.map(|e| {
|
||||||
|
let err = e.err().unwrap();
|
||||||
|
warn!("Error occured in Filesystem operation: {}", err);
|
||||||
|
err
|
||||||
|
})
|
||||||
|
.collect::<Vec<StorageBackendError>>();
|
||||||
|
|
||||||
|
let nerrs = errs.len();
|
||||||
|
|
||||||
|
if nerrs != 0 {
|
||||||
|
warn!("{} Errors occured while removing {} files", nerrs, nfiles);
|
||||||
|
let moderr = ModuleError::new("File removal failed");
|
||||||
|
|
||||||
|
// TODO : Collect StorageBackendErrors
|
||||||
|
|
||||||
|
Err(moderr)
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue