From 4f83b22b982ca3b5fe93704bf305a18f556e9b3d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 22 Sep 2016 08:39:00 +0200 Subject: [PATCH] Fix Store::move_by_id(): Move in cache as well --- libimagstore/src/store.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 68cf3d7a..5f3c15c8 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -662,11 +662,15 @@ impl Store { } { - let hsmap = match self.entries.write() { + let mut hsmap = match self.entries.write() { Err(_) => return Err(SE::new(SEK::LockPoisoned, None)), Ok(m) => m, }; + if hsmap.contains_key(&new_id) { + return Err(SEK::EntryAlreadyExists.into_error()); + } + if !hsmap.contains_key(&old_id) { return Err(SE::new(SEK::EntryAlreadyBorrowed, None)); } else { @@ -675,7 +679,13 @@ impl Store { match FileAbstraction::rename(&old_id_pb, &new_id_pb) { Err(e) => return Err(SEK::EntryRenameError.into_error_with_cause(Box::new(e))), Ok(_) => { - debug!("Rename worked"); + debug!("Rename worked on filesystem"); + + // assert enforced through check hsmap.contains_key(&new_id) above. + // Should therefor never fail + assert!(hsmap + .remove(&old_id) + .and_then(|entry| hsmap.insert(new_id.clone(), entry)).is_none()) } } } @@ -2395,7 +2405,8 @@ mod store_tests { assert!(r.map_err(|e| println!("ERROR: {:?}", e)).is_ok()); { - assert!(store.entries.read().unwrap().get(&id_mv).is_some()); + let id_mv_with_base = id_mv.clone().with_base(store.path().clone()); + assert!(store.entries.read().unwrap().get(&id_mv_with_base).is_some()); } } }