From 009b608871de302ab04e1b664727958df8cbafba Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 3 Jan 2020 12:04:40 +0100 Subject: Add Store::is_borrowed(StoreId) Add a function to Store to check whether a StoreId is borrowed. Signed-off-by: Matthias Beyer --- lib/core/libimagstore/src/store.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 26612965..5137b517 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -216,6 +216,18 @@ impl Store { Ok(store) } + pub fn is_borrowed(&self, id: S) -> Result { + let id = id.into_storeid()?; + debug!("Checking whether id is borrowed: '{}'", id); + + self.entries + .read() + .map_err(|_| Error::from(EM::LockError)) + .context(format_err!("Error while checking whether {} is borrowed", id)) + .map(|cache| cache.get(&id).map(|e| e.is_borrowed()).unwrap_or(false)) + .map_err(Error::from) + } + /// Creates the Entry at the given location (inside the entry) /// /// # Return value -- cgit v1.2.3