From 98dab06b06e91cd1553b765b9b7c09da9129c050 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 31 May 2024 11:51:50 -0300 Subject: [PATCH] auto create config'd patch directory if it's missing --- src/patch_server/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/patch_server/src/lib.rs b/src/patch_server/src/lib.rs index ecf51f9..06f72e9 100644 --- a/src/patch_server/src/lib.rs +++ b/src/patch_server/src/lib.rs @@ -217,7 +217,13 @@ impl ServerState for PatchServerState { } fn load_patch_dir(basedir: &str, patchbase: &str, file_ids: &mut HashMap) -> PatchFileTree { - let paths = fs::read_dir(basedir).expect("could not read directory"); + let paths = match fs::read_dir(basedir) { + Ok(d) => d, + Err(_) => { + fs::create_dir_all(basedir).expect(&format!("Patch directory \"{}\" is missing and could not be created.", basedir)); + fs::read_dir(basedir).expect(&format!("Patch directory \"{}\" was created but could not be read!", basedir)) // how ?? + }, + }; let mut files = Vec::new(); let mut dirs = Vec::new();