diff --git a/bin/core/imag-link/src/main.rs b/bin/core/imag-link/src/main.rs index 8f839f90..cb40de5c 100644 --- a/bin/core/imag-link/src/main.rs +++ b/bin/core/imag-link/src/main.rs @@ -394,7 +394,7 @@ mod tests { #[test] fn test_link_modificates() { setup_logging(); - let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) + let rt = generate_test_runtime(vec!["test1", "test2"]) .unwrap(); debug!("Runtime created"); @@ -423,7 +423,7 @@ mod tests { #[test] fn test_linking_links() { setup_logging(); - let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) + let rt = generate_test_runtime(vec!["test1", "test2"]) .unwrap(); debug!("Runtime created"); @@ -452,7 +452,7 @@ mod tests { #[test] fn test_multilinking() { setup_logging(); - let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) + let rt = generate_test_runtime(vec!["test1", "test2"]) .unwrap(); debug!("Runtime created"); @@ -482,7 +482,7 @@ mod tests { #[test] fn test_linking_more_than_two() { setup_logging(); - let rt = generate_test_runtime(vec!["internal", "test1", "test2", "test3"]) + let rt = generate_test_runtime(vec!["test1", "test2", "test3"]) .unwrap(); debug!("Runtime created"); @@ -519,7 +519,7 @@ mod tests { #[test] fn test_linking_links_unlinking_removes_links() { setup_logging(); - let rt = generate_test_runtime(vec!["internal", "test1", "test2"]) + let rt = generate_test_runtime(vec!["test1", "test2"]) .unwrap(); debug!("Runtime created"); @@ -555,7 +555,7 @@ mod tests { #[test] fn test_linking_and_unlinking_more_than_two() { setup_logging(); - let rt = generate_test_runtime(vec!["internal", "test1", "test2", "test3"]) + let rt = generate_test_runtime(vec!["test1", "test2", "test3"]) .unwrap(); debug!("Runtime created"); diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs index 303f89d7..03b5cb86 100644 --- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs +++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs @@ -137,7 +137,7 @@ impl FileAbstraction for InMemoryFileAbstraction { let mut mtx = self.backend().lock().expect("Locking Mutex failed"); let backend = mtx.get_mut(); - let a = backend.get(from).cloned().ok_or_else(|| SE::from_kind(SEK::FileNotFound))?; + let a = backend.remove(from).ok_or_else(|| SE::from_kind(SEK::FileNotFound))?; backend.insert(to.clone(), a); debug!("Renaming: {:?} -> {:?} worked", from, to); Ok(()) diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 79236655..36532cec 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 @@ -1183,8 +1190,8 @@ mod store_tests { assert!(store.create(id.clone()).is_ok()); } + let id_with_base = id.clone().with_base(store.path().clone()); { - let id_with_base = id.clone().with_base(store.path().clone()); assert!(store.entries.read().unwrap().get(&id_with_base).is_some()); } @@ -1196,8 +1203,16 @@ mod store_tests { assert!(store.entries.read().unwrap().get(&id_mv_with_base).is_some()); } - assert!(match store.get(id.clone()) { Ok(None) => true, _ => false }, - "Moved id ({:?}) is still there", id); + { + let pb = id_with_base.into_pathbuf().unwrap(); + let exists = store.backend.exists(&pb).unwrap(); + assert!(!exists, "Old entry exists in Filesystem, but shouldn't"); + } + + let result = store.get(id.clone()); + + assert!(match result { Ok(None) => true, _ => false }, + "Moved id ({:?}) is still there: {:?}", id, result); assert!(match store.get(id_mv.clone()) { Ok(Some(_)) => true, _ => false }, "New id ({:?}) is not in store...", id_mv); } diff --git a/lib/etc/libimagutil/src/testing.rs b/lib/etc/libimagutil/src/testing.rs index b060a466..70ec7915 100644 --- a/lib/etc/libimagutil/src/testing.rs +++ b/lib/etc/libimagutil/src/testing.rs @@ -96,7 +96,7 @@ macro_rules! make_mock_app { #[allow(unused)] pub fn generate_test_runtime<'a>(mut args: Vec<&'static str>) -> Result, RuntimeError> { - let mut cli_args = vec![$appname, "--rtp", "/tmp"]; + let mut cli_args = vec![$appname]; cli_args.append(&mut args);