auto create usercontent path and throw panic only if it is not a directory
This commit is contained in:
parent
c6e1f80b47
commit
355f05320b
|
@ -3,7 +3,7 @@
|
||||||
This file provides the `loadenv` function that will do just that.
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Redis {
|
pub struct Redis {
|
||||||
|
@ -45,7 +45,10 @@ pub fn loadenv() -> Result<Env, Box<dyn std::error::Error>> {
|
||||||
let spath: String = get_var("USERCONTENT_DIR")?;
|
let spath: String = get_var("USERCONTENT_DIR")?;
|
||||||
let path = Path::new(&spath);
|
let path = Path::new(&spath);
|
||||||
if ! path.exists() {
|
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
|
spath
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue