Merge pull request #1123 from matthiasbeyer/libimagstore/fix-move
libimagstore: fix move
This commit is contained in:
commit
389f24d51f
2 changed files with 17 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)),
|
||||
|
|
Loading…
Reference in a new issue