Fix: Create directory before renaming file
This commit is contained in:
parent
24210c0068
commit
b587bbbdc1
1 changed files with 12 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue