diff --git a/libimagstore/src/error.rs b/libimagstore/src/error.rs index 9dc48bb5..eabb26b7 100644 --- a/libimagstore/src/error.rs +++ b/libimagstore/src/error.rs @@ -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", } } diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 74ffcc58..9c92980a 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -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> { - 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