From 355f05320b37419756a0859e227d54fa8f923d57 Mon Sep 17 00:00:00 2001 From: blek Date: Sun, 1 Oct 2023 14:43:04 +1000 Subject: [PATCH] auto create usercontent path and throw panic only if it is not a directory --- filed/src/env.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/filed/src/env.rs b/filed/src/env.rs index c1a7d43..f2cf1e5 100644 --- a/filed/src/env.rs +++ b/filed/src/env.rs @@ -3,7 +3,7 @@ This file provides the `loadenv` function that will do just that. */ -use std::{env::var, net::SocketAddr, path::Path}; +use std::{env::var, net::SocketAddr, path::Path, fs}; #[derive(Debug, Clone)] pub struct Redis { @@ -45,7 +45,10 @@ pub fn loadenv() -> Result> { let spath: String = get_var("USERCONTENT_DIR")?; let path = Path::new(&spath); if ! path.exists() { - return Err(format!("USERCONTENT_DIR is set to \"{}\", which does not exist!", &spath).into()) + fs::create_dir_all(path)?; + } + if ! path.is_dir() { + return Err(format!("USERCONTENT_DIR is set to \"{}\", which exists but is not a directory!", &spath).into()) } spath }