Implement Store::retrieve

This commit is contained in:
Marcel Müller 2016-01-17 16:58:58 +01:00
parent 3aa4b8115b
commit d949cddc65
No known key found for this signature in database
GPG key ID: DD4ED37D0CAC76E2
2 changed files with 11 additions and 1 deletions

View file

@ -17,6 +17,7 @@ pub enum StoreErrorKind {
FileNotCreated,
StorePathExists,
StorePathCreate,
LockPoisoned,
// maybe more
}
@ -30,6 +31,8 @@ fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str {
&StoreErrorKind::FileNotCreated => "File corresponding to ID could not be created",
&StoreErrorKind::StorePathExists => "Store path exists",
&StoreErrorKind::StorePathCreate => "Store path create",
&StoreErrorKind::LockPoisoned
=> "The internal Store Lock has been poisoned",
}
}

View file

@ -83,7 +83,14 @@ impl Store {
/// Borrow a given Entry. When the `FileLockEntry` is either `update`d or
/// dropped, the new Entry is written to disk
pub fn retrieve<'a>(&'a self, id: StoreId) -> Result<FileLockEntry<'a>> {
unimplemented!();
let hsmap = self.entries.write();
if hsmap.is_err() {
return Err(StoreError::new(StoreErrorKind::LockPoisoned, None))
}
hsmap.unwrap().get_mut(&id)
.ok_or(StoreError::new(StoreErrorKind::IdNotFound, None))
.and_then(|store_entry| store_entry.get_entry())
.and_then(|entry| Ok(FileLockEntry::new(self, entry, id)))
}
/// Return the `FileLockEntry` and write to disk