Merge pull request #1123 from matthiasbeyer/libimagstore/fix-move

libimagstore: fix move
This commit is contained in:
Matthias Beyer 2017-10-01 10:06:08 +02:00 committed by GitHub
commit 389f24d51f
2 changed files with 17 additions and 0 deletions

View file

@ -126,10 +126,23 @@ impl FileAbstraction for FSFileAbstraction {
} }
fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> { 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) rename(from, to).chain_err(|| SEK::FileNotRenamed)
} }
fn create_dir_all(&self, path: &PathBuf) -> Result<(), SE> { fn create_dir_all(&self, path: &PathBuf) -> Result<(), SE> {
debug!("Creating: {:?}", path);
create_dir_all(path).chain_err(|| SEK::DirNotCreated) create_dir_all(path).chain_err(|| SEK::DirNotCreated)
} }

View file

@ -766,6 +766,7 @@ impl Store {
if hsmap.contains_key(&new_id) { if hsmap.contains_key(&new_id) {
return Err(SE::from_kind(SEK::EntryAlreadyExists(new_id.clone()))); 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 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 // 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()))); 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 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()); let new_id_pb = try!(new_id.clone().with_base(self.path().clone()).into_pathbuf());
if try!(self.backend.exists(&new_id_pb)) { if try!(self.backend.exists(&new_id_pb)) {
return Err(SE::from_kind(SEK::EntryAlreadyExists(new_id.clone()))); 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) { 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)), Err(e) => return Err(e).chain_err(|| SEK::EntryRenameError(old_id_pb, new_id_pb)),