Refactor get_file_by_id() into smaller functions
This commit is contained in:
parent
1b1f0678cb
commit
2ed2b17b85
1 changed files with 3 additions and 11 deletions
|
@ -124,18 +124,10 @@ impl StorageBackend {
|
||||||
pub fn get_file_by_id<'a, HP>(&self, id: FileID, p: &Parser<HP>) -> Option<File>
|
pub fn get_file_by_id<'a, HP>(&self, id: FileID, p: &Parser<HP>) -> Option<File>
|
||||||
where HP: FileHeaderParser<'a>
|
where HP: FileHeaderParser<'a>
|
||||||
{
|
{
|
||||||
let path = self.build_filepath_with_id(id);
|
if let Ok(fs) = FSFile::open(self.build_filepath_with_id(id)) {
|
||||||
if let Ok(file) = FSFile::open(path) {
|
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
file.read_to_string(&mut s);
|
fs.read_to_string(&mut s);
|
||||||
let parser_out = p.read(s);
|
p.read(s).and_then(|(h, d)| Ok(File::from_parser_result(id, h, d))).ok()
|
||||||
if let Ok((header, data)) = parser_out {
|
|
||||||
Some(File::from_parser_result(id, header, data))
|
|
||||||
} else {
|
|
||||||
info!("Cannot build File from ID '{}'. Parser Error:\n{}",
|
|
||||||
id, parser_out.err().unwrap());
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue