From 09c543eee3dbc361627e4ad6b5f5f55317ff334b Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sun, 17 Jul 2022 17:07:53 +0200 Subject: [PATCH] create all required directories on startup --- planetwars-server/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs index 123fdab..8962c3e 100644 --- a/planetwars-server/src/lib.rs +++ b/planetwars-server/src/lib.rs @@ -8,7 +8,8 @@ pub mod routes; pub mod schema; pub mod util; -use std::net::SocketAddr; +use std::path::PathBuf; +use std::{net::SocketAddr, fs}; use std::ops::Deref; use std::sync::Arc; @@ -93,6 +94,19 @@ pub async fn prepare_db(config: &GlobalConfig) -> DbPool { pool } +// create all directories required for further operation +fn init_directories(config: &GlobalConfig) -> std::io::Result<()> { + fs::create_dir_all(&config.bots_directory)?; + fs::create_dir_all(&config.maps_directory)?; + fs::create_dir_all(&config.match_logs_directory)?; + + let registry_path = PathBuf::from(&config.registry_directory); + fs::create_dir_all(registry_path.join("sha256"))?; + fs::create_dir_all(registry_path.join("manifests"))?; + fs::create_dir_all(registry_path.join("uploads"))?; + Ok(()) +} + pub fn api() -> Router { Router::new() .route("/register", post(routes::users::register)) @@ -145,6 +159,7 @@ async fn run_registry(config: Arc, db_pool: DbPool) { pub async fn run_app() { let global_config = Arc::new(get_config().unwrap()); let db_pool = prepare_db(&global_config).await; + init_directories(&global_config).unwrap(); tokio::spawn(run_ranker(global_config.clone(), db_pool.clone())); tokio::spawn(run_registry(global_config.clone(), db_pool.clone()));