From b6af948c0ea1fa10dd168fa60ce9952da136b754 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 24 Nov 2015 10:59:30 +0100 Subject: [PATCH] Implement Storage::get_file_by_id() --- src/storage/backend.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/storage/backend.rs b/src/storage/backend.rs index 055c58e0..ec3aa3da 100644 --- a/src/storage/backend.rs +++ b/src/storage/backend.rs @@ -121,7 +121,17 @@ impl StorageBackend { * TODO: Needs refactoring, as there might be an error when reading from * disk OR the id just does not exist. */ - pub fn get_file_by_id(id: FileID) -> Option { + pub fn get_file_by_id<'a, HP>(&self, id: FileID, p: &Parser) -> Option + 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 {