aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-07-17 17:07:53 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-07-17 17:07:53 +0200
commit09c543eee3dbc361627e4ad6b5f5f55317ff334b (patch)
tree1bc015228c185454c88f0122bf3698e6f9c1dada /planetwars-server
parentc16b068f8b3848e775f2490851fbc788139febe0 (diff)
downloadplanetwars.dev-09c543eee3dbc361627e4ad6b5f5f55317ff334b.tar.xz
planetwars.dev-09c543eee3dbc361627e4ad6b5f5f55317ff334b.zip
create all required directories on startup
Diffstat (limited to 'planetwars-server')
-rw-r--r--planetwars-server/src/lib.rs17
1 files changed, 16 insertions, 1 deletions
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<GlobalConfig>, 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()));