From 0695434ca0e2816d6492fca73a212a60905dac9c Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Sun, 24 Nov 2019 16:39:15 +0100 Subject: [PATCH] fix: recursively create directories instead of failing e.g. when ~/.config does not exist --- src/config.rs | 4 ++-- src/main.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 2726b85..9352944 100644 --- a/src/config.rs +++ b/src/config.rs @@ -57,7 +57,7 @@ pub fn config_path(file: &str) -> PathBuf { fs::remove_file(cfg_dir).expect("unable to remove old config file"); } if !cfg_dir.exists() { - fs::create_dir(cfg_dir).expect("can't create config folder"); + fs::create_dir_all(cfg_dir).expect("can't create config folder"); } let mut cfg = cfg_dir.to_path_buf(); cfg.push(file); @@ -68,7 +68,7 @@ pub fn cache_path(file: &str) -> PathBuf { let proj_dirs = proj_dirs(); let cache_dir = proj_dirs.cache_dir(); if !cache_dir.exists() { - fs::create_dir(cache_dir).expect("can't create cache folder"); + fs::create_dir_all(cache_dir).expect("can't create cache folder"); } let mut pb = cache_dir.to_path_buf(); pb.push(file); diff --git a/src/main.rs b/src/main.rs index 58d00ed..cc7dc57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -146,7 +146,7 @@ fn main() { if let Some(basepath) = matches.value_of("basepath") { let path = PathBuf::from_str(basepath).expect("invalid path"); if !path.exists() { - fs::create_dir(&path).expect("could not create basepath directory"); + fs::create_dir_all(&path).expect("could not create basepath directory"); } *config::BASE_PATH.write().unwrap() = Some(path); }