diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 79236655..b4d91dd8 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -229,10 +229,16 @@ impl Store { debug!("Creating id: '{}'", id); - let exists = id.exists()? || self.entries + let exists = self.entries .read() - .map(|map| map.contains_key(&id)) .map_err(|_| SE::from_kind(SEK::LockPoisoned)) + .map(|map| map.contains_key(&id)) + .and_then(|exists| if exists { + Ok(exists) + } else { + let pb = id.clone().into_pathbuf().map_err(SE::from)?; + self.backend.exists(&pb) + }) .chain_err(|| SEK::CreateCallError(id.clone()))?; if exists { @@ -314,10 +320,16 @@ impl Store { debug!("Getting id: '{}'", id); - let exists = id.exists()? || self.entries + let exists = self.entries .read() - .map(|map| map.contains_key(&id)) .map_err(|_| SE::from_kind(SEK::LockPoisoned)) + .map(|map| map.contains_key(&id)) + .and_then(|exists| if exists { + Ok(exists) + } else { + let pb = id.clone().into_pathbuf().map_err(SE::from)?; + self.backend.exists(&pb) + }) .chain_err(|| SEK::GetCallError(id.clone()))?; if !exists { @@ -461,12 +473,7 @@ impl Store { debug!("Deleting id: '{}'", id); - // Small optimization: We need the pathbuf for deleting, but when calling - // StoreId::exists(), a PathBuf object gets allocated. So we simply get a - // PathBuf here, check whether it is there and if it is, we can re-use it to - // delete the filesystem file. let pb = id.clone().into_pathbuf()?; - { let mut entries = self .entries