FS backend: Safe allocation of new PathBuf object
::stf::fs::create_dir_all() takes any ref to `Path`, which is what we have here, so we can leave out the allocation of a new PathBuf object here. Also remove the match by a `if let Some(_)`, which increases the readability a bit. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
88a4eee087
commit
582fd10acb
1 changed files with 7 additions and 8 deletions
|
@ -105,15 +105,14 @@ impl FileAbstraction for FSFileAbstraction {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<()> {
|
fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<()> {
|
||||||
match to.parent() {
|
if let Some(p) = to.parent() {
|
||||||
Some(p) => if !p.exists() {
|
if !p.exists() {
|
||||||
debug!("Creating: {:?}", p);
|
debug!("Creating: {:?}", p);
|
||||||
let _ = create_dir_all(&PathBuf::from(p)).context(EM::DirNotCreated)?;
|
let _ = create_dir_all(&p).context(EM::DirNotCreated)?;
|
||||||
},
|
}
|
||||||
None => {
|
} else {
|
||||||
debug!("Failed to find parent. This looks like it will fail now");
|
debug!("Failed to find parent. This looks like it will fail now");
|
||||||
//nothing
|
//nothing
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Renaming {:?} to {:?}", from, to);
|
debug!("Renaming {:?} to {:?}", from, to);
|
||||||
|
|
Loading…
Reference in a new issue