Auto merge of #45 - matthiasbeyer:bm-command-output, r=matthiasbeyer

Bm command output

Add info-output to some BM commands.
This commit is contained in:
Homu 2016-01-03 00:30:10 +09:00
commit a2037f3909

View file

@ -58,11 +58,28 @@ impl<'a> BM<'a> {
debug!(" tags = '{:?}'", tags); debug!(" tags = '{:?}'", tags);
let header = build_header(url, tags); let header = build_header(url, tags);
let fileid = self.rt.store().new_file_with_header(self, header); let fileid = self.rt
self.rt.store().load(self, &parser, &fileid).and_then(|file| { .store()
info!("Created file in memory: {}", fileid); .new_file_with_header(self, header);
Some(self.rt.store().persist(&parser, file))
}).unwrap_or(false) let result = self.rt
.store()
.load(self, &parser, &fileid)
.map(|file| {
info!("Created file in memory: {}", fileid);
self.rt
.store()
.persist(&parser, file)
})
.unwrap_or(false);
if result {
info!("Adding worked");
} else {
info!("Adding failed");
}
result
} }
fn validate_url<HP>(&self, url: &String, parser: &Parser<HP>) -> bool fn validate_url<HP>(&self, url: &String, parser: &Parser<HP>) -> bool
@ -185,15 +202,21 @@ impl<'a> BM<'a> {
let f = file.deref().borrow(); let f = file.deref().borrow();
self.rt.store().remove(f.id().clone()) self.rt.store().remove(f.id().clone())
}) })
.all(|x| x); .fold((0, 0), |acc, succeeded| {
let (worked, failed) = acc;
if succeeded {
(worked + 1, failed)
} else {
(worked, failed + 1)
}
});
if result { let (worked, failed) = result;
info!("Removing succeeded");
} else {
info!("Removing failed");
}
return result; info!("Removing succeeded for {} files", worked);
info!("Removing failed for {} files", failed);
return failed == 0;
} }
/** /**