Fix: In-Memory filesystem backend did not remove on rename

The implementation of the in-memory filesystem for testing imag code did
not actually use `HashMap::remove()` when an entry was moved, but
`HashMap::get().cloned()`, which caused the original entry to exist
_after_ the move.

I'm not sure why this did not fail much earlier, but it was clearly
wrong. This commit adjust the test to check the "filesystem" before
checking the store and fixes the bug.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2018-10-09 00:46:28 +02:00
parent 8e232523b2
commit cc11162dd4
2 changed files with 12 additions and 4 deletions

View file

@ -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(())

View file

@ -1190,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());
}
@ -1203,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);
}