diff --git a/lib/core/libimagstore/src/file_abstraction/fs.rs b/lib/core/libimagstore/src/file_abstraction/fs.rs index 48c51ebb..de292925 100644 --- a/lib/core/libimagstore/src/file_abstraction/fs.rs +++ b/lib/core/libimagstore/src/file_abstraction/fs.rs @@ -126,10 +126,23 @@ impl FileAbstraction for FSFileAbstraction { } fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> { + match to.parent() { + Some(p) => if !p.exists() { + debug!("Creating: {:?}", p); + let _ = try!(create_dir_all(&PathBuf::from(p))); + }, + None => { + debug!("Failed to find parent. This looks like it will fail now"); + //nothing + }, + } + + debug!("Renaming {:?} to {:?}", from, to); rename(from, to).chain_err(|| SEK::FileNotRenamed) } fn create_dir_all(&self, path: &PathBuf) -> Result<(), SE> { + debug!("Creating: {:?}", path); create_dir_all(path).chain_err(|| SEK::DirNotCreated) } diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 90cfa6e9..c376ecce 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -766,6 +766,7 @@ impl Store { if hsmap.contains_key(&new_id) { return Err(SE::from_kind(SEK::EntryAlreadyExists(new_id.clone()))); } + debug!("New id does not exist in cache"); // if we do not have an entry here, we fail in `FileAbstraction::rename()` below. // if we have one, but it is borrowed, we really should not rename it, as this might @@ -774,12 +775,15 @@ impl Store { return Err(SE::from_kind(SEK::EntryAlreadyBorrowed(old_id.clone()))); } + debug!("Old id is not yet borrowed"); + let old_id_pb = try!(old_id.clone().with_base(self.path().clone()).into_pathbuf()); let new_id_pb = try!(new_id.clone().with_base(self.path().clone()).into_pathbuf()); if try!(self.backend.exists(&new_id_pb)) { return Err(SE::from_kind(SEK::EntryAlreadyExists(new_id.clone()))); } + debug!("New entry does not yet exist on filesystem. Good."); match self.backend.rename(&old_id_pb, &new_id_pb) { Err(e) => return Err(e).chain_err(|| SEK::EntryRenameError(old_id_pb, new_id_pb)),