From ab30279375561c72aa68b04ce7b03a56c316d6c2 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 10 Jun 2023 14:08:58 -0700 Subject: [PATCH] Create data directory if not exists --- src/utils.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils.rs b/src/utils.rs index bcae7f5..6bf9581 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -67,6 +67,10 @@ pub fn get_submission_data(challenge: i32) -> Vec { json } Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => { + // Create parent directory if not exists + if let Some(parent_dir) = std::path::Path::new(&submission_data_path).parent() { + fs::create_dir_all(parent_dir).unwrap(); + } let mut file = File::create(&submission_data_path).unwrap(); file.write_all(b"[]").unwrap(); file.flush().unwrap();