From d1078590c79e8ff2b836c08acfa9226118cc7975 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 26 Oct 2019 09:46:39 +0200 Subject: [PATCH] Fix: Testing backend bug where an entry was not properly rewritten When moving an entry, what we did is copying the entry inside the backend abstraction (the hashmap) from one key to another. But as the entry itself does also encode its location, we actually have to rewrite the entire entry. This patch fixes this. Signed-off-by: Matthias Beyer --- .../libimagstore/src/file_abstraction/inmemory.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs index d8c7980b..9aa677b1 100644 --- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs +++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs @@ -28,6 +28,7 @@ use libimagerror::errors::ErrorMsg as EM; use failure::Fallible as Result; use failure::Error; +use failure::err_msg; use super::FileAbstraction; use super::FileAbstractionInstance; @@ -137,7 +138,18 @@ impl FileAbstraction for InMemoryFileAbstraction { let backend = mtx.get_mut(); let a = backend.remove(from).ok_or_else(|| EM::FileNotFound)?; - backend.insert(to.clone(), a); + let new_entry = { + let new_location = if to.starts_with("/") { + let s = to.to_str().map(String::from).ok_or_else(|| err_msg("Failed to convert path to str"))?; + PathBuf::from(s.replace("/", "")) + } else { + to.to_path_buf() + }; + + Entry::from_str(crate::storeid::StoreId::new(new_location)?, &a.to_str()?)? + }; + + backend.insert(to.clone(), new_entry); debug!("Renaming: {:?} -> {:?} worked", from, to); Ok(()) }