From d949cddc650fb2fd0f87d81307b11815e8230db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sun, 17 Jan 2016 16:58:58 +0100 Subject: [PATCH] Implement Store::retrieve --- libimagstore/src/error.rs | 3 +++ libimagstore/src/store.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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