diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-10-26 09:46:39 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-10-26 09:57:05 +0200 |
commit | d1078590c79e8ff2b836c08acfa9226118cc7975 (patch) | |
tree | 41a51ec2daa47d25dad7c8c0afae217f590e34d0 /lib/core | |
parent | a07e03a25cada785ed1f013a193b836c463c2b82 (diff) |
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 <mail@beyermatthias.de>
Diffstat (limited to 'lib/core')
-rw-r--r-- | lib/core/libimagstore/src/file_abstraction/inmemory.rs | 14 |
1 files changed, 13 insertions, 1 deletions
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(()) } |