Implement Storage::get_file_by_id()

This commit is contained in:
Matthias Beyer 2015-11-24 10:59:30 +01:00
parent 176183e718
commit b6af948c0e

View file

@ -121,7 +121,17 @@ impl StorageBackend {
* TODO: Needs refactoring, as there might be an error when reading from * TODO: Needs refactoring, as there might be an error when reading from
* disk OR the id just does not exist. * disk OR the id just does not exist.
*/ */
pub fn get_file_by_id(id: FileID) -> Option<File> { pub fn get_file_by_id<'a, HP>(&self, id: FileID, p: &Parser<HP>) -> Option<File>
where HP: FileHeaderParser<'a>
{
let path = self.build_filepath_with_id(id);
if let Ok(file) = FSFile::open(path) {
let mut s = String::new();
file.read_to_string(&mut s);
File::from_parser_result(id, p.read(s))
} else {
None
}
} }
fn build_filepath(&self, f: &File) -> String { fn build_filepath(&self, f: &File) -> String {