Implement Store::retrieve
This commit is contained in:
parent
3aa4b8115b
commit
d949cddc65
2 changed files with 11 additions and 1 deletions
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue