From 6751c34f1bdb7f30a24b312f62e4f3d140ccc6d3 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 7 Oct 2018 15:08:25 +0200 Subject: [PATCH] Fix: Remove call to deprecated function This actually caused tests to fail if there was indeed a file at /tmp/store/test and the test tried to create a "test" entry in the store. Do use backend instead to check whether entry actually exists. Signed-off-by: Matthias Beyer --- lib/core/libimagstore/src/store.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) 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