Fix: Create directory before renaming file

This commit is contained in:
Matthias Beyer 2017-10-01 01:59:41 +02:00
parent 24210c0068
commit b587bbbdc1

View file

@ -126,6 +126,18 @@ 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)
}