summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-12-13 01:27:12 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-12-13 22:49:33 +0100
commit4fe7fd366c20b980e584fdd9dbbbec9b8bdf62b1 (patch)
tree647af2ecb4f53c1697162fc109be807692f10772
parentccd8e94fbfc9d8b1af6e074ec86b5668c76f3527 (diff)
downloadimag-4fe7fd366c20b980e584fdd9dbbbec9b8bdf62b1.zip
imag-4fe7fd366c20b980e584fdd9dbbbec9b8bdf62b1.tar.gz
Add Store::exists() for checking whether a StoreId exists as Entry
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/core/libimagstore/src/store.rs32
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs
index 36904a3..4546f1c 100644
--- a/lib/core/libimagstore/src/store.rs
+++ b/lib/core/libimagstore/src/store.rs
@@ -222,13 +222,7 @@ impl Store {
debug!("Creating id: '{}'", id);
- let exists =
- self.entries
- .read()
- .map(|map| map.contains_key(&id))
- .map_err(|_| Error::from(EM::LockError))
- .context(format_err!("CreateCallError: {}", id))? ||
- self.backend.exists(&id.clone().into_pathbuf()?)?;
+ let exists = self.exists(id.clone())?;
if exists {
debug!("Entry exists: {:?}", id);
@@ -306,14 +300,7 @@ impl Store {
debug!("Getting id: '{}'", id);
- let exists =
- self.entries
- .read()
- .map(|map| map.contains_key(&id))
- .map_err(|_| Error::from(EM::LockError))
- .context(format_err!("CreateCallError: {}", id))? ||
- self.backend.exists(&id.clone().into_pathbuf()?)?;
-
+ let exists = self.exists(id.clone())?;
if !exists {
debug!("Does not exist in internal cache or filesystem: {:?}", id);
@@ -648,6 +635,21 @@ impl Store {
.map(|i| Entries::new(i, self))
}
+ /// Check whether the store has the Entry pointed to by the StoreId `id`
+ pub fn exists<'a>(&'a self, id: StoreId) -> Result<bool> {
+ let cache_has_entry = |id: &StoreId|
+ self.entries
+ .read()
+ .map(|map| map.contains_key(id))
+ .map_err(|_| Error::from(EM::LockError))
+ .context(format_err!("CreateCallError: {}", id));
+
+ let backend_has_entry = |id: StoreId|
+ self.backend.exists(&id.with_base(self.path().to_path_buf()).into_pathbuf()?);
+
+ Ok(cache_has_entry(&id)? || backend_has_entry(id)?)
+ }
+
/// Gets the path where this store is on the disk
pub fn path(&self) -> &PathBuf {
&self.location