From 355ec697c19bf55cb4aaca78d1d88cb46737581e Mon Sep 17 00:00:00 2001 From: Julian Ganz Date: Mon, 25 Jan 2016 22:26:00 +0100 Subject: [PATCH] Implement Store::retrieve_copy() --- libimagstore/src/store.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index e8fbbb98..6a4cb735 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -187,7 +187,19 @@ impl Store { /// Retrieve a copy of a given entry, this cannot be used to mutate /// the one on disk pub fn retrieve_copy(&self, id: StoreId) -> Result { - unimplemented!(); + let mut entries_lock = self.entries.write(); + if entries_lock.is_err() { + return Err(StoreError::new(StoreErrorKind::LockPoisoned, None)) + } + + let mut entries = entries_lock.unwrap(); + + // if the entry is currently modified by the user, we cannot drop it + if entries.get(&id).map(|e| e.is_borrowed()).unwrap_or(false) { + return Err(StoreError::new(StoreErrorKind::IdLocked, None)); + } + + StoreEntry::new(id).get_entry() } /// Delete an entry