summaryrefslogtreecommitdiffstats
path: root/lib/core
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-11-06 18:37:53 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-11-06 18:37:53 +0100
commit582fd10acb1750a9fdbc38a4705e7691d416faf7 (patch)
tree1a60d7fffbf2bfb8cfd60d50974c20ff1f37a1ed /lib/core
parent88a4eee08760fcb59453f7b69f5d0b7ff300705d (diff)
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>
Diffstat (limited to 'lib/core')
-rw-r--r--lib/core/libimagstore/src/file_abstraction/fs.rs15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/core/libimagstore/src/file_abstraction/fs.rs b/lib/core/libimagstore/src/file_abstraction/fs.rs
index 131edcba..189032ba 100644
--- a/lib/core/libimagstore/src/file_abstraction/fs.rs
+++ b/lib/core/libimagstore/src/file_abstraction/fs.rs
@@ -105,15 +105,14 @@ impl FileAbstraction for FSFileAbstraction {
}
fn rename(&self, from: &PathBuf, to: &PathBuf) -> Result<()> {
- match to.parent() {
- Some(p) => if !p.exists() {
+ if let Some(p) = to.parent() {
+ if !p.exists() {
debug!("Creating: {:?}", p);
- let _ = create_dir_all(&PathBuf::from(p)).context(EM::DirNotCreated)?;
- },
- None => {
- debug!("Failed to find parent. This looks like it will fail now");
- //nothing
- },
+ let _ = create_dir_all(&p).context(EM::DirNotCreated)?;
+ }
+ } else {
+ debug!("Failed to find parent. This looks like it will fail now");
+ //nothing
}
debug!("Renaming {:?} to {:?}", from, to);