From b9bbe06d90f0306e408163b137422534f8d76e07 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 11 Jul 2024 07:27:11 +0100 Subject: [PATCH] refactor: split server storage creation out from startup Closes kemitix/git-next#75 --- crates/server-actor/src/lib.rs | 44 ++++++++++++++++++---------------- crates/server/src/lib.rs | 1 - 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/crates/server-actor/src/lib.rs b/crates/server-actor/src/lib.rs index 8ccfbc7..15dcb0d 100644 --- a/crates/server-actor/src/lib.rs +++ b/crates/server-actor/src/lib.rs @@ -65,7 +65,6 @@ impl Handler for Server { impl Handler for Server { type Result = (); - #[allow(clippy::cognitive_complexity)] // TODO: (#75) reduce complexity fn handle(&mut self, msg: ReceiveServerConfig, _ctx: &mut Self::Context) -> Self::Result { let Ok(socket_addr) = msg.http() else { warn!("Unable to parse http.addr"); @@ -76,27 +75,9 @@ impl Handler for Server { } self.generation.inc(); let server_config = msg; - // Server Storage - let dir = server_config.storage().path(); - if !dir.exists() { - info!(?dir, "server storage doesn't exist - creating it"); - if let Err(err) = self.fs.dir_create(dir) { - error!(?err, ?dir, "Failed to create server storage"); - return; - } - } - let Ok(canon) = dir.canonicalize() else { - error!(?dir, "Failed to confirm server storage"); + let Some(server_storage) = self.server_storage(&server_config) else { return; }; - info!(dir = ?canon, "server storage"); - - // Forge directories in Server Storage - let server_storage = server_config.storage(); - if let Err(err) = self.create_forge_data_directories(&server_config, dir) { - error!(?err, "Failure creating forge storage"); - return; - } // Webhook Server info!("Starting Webhook Server..."); @@ -247,4 +228,27 @@ impl Server { info!("Started"); (repo_alias, addr) } + + fn server_storage<'cfg>( + &self, + server_config: &'cfg ReceiveServerConfig, + ) -> Option<&'cfg ServerStorage> { + let server_storage = server_config.storage(); + let dir = server_storage.path(); + if !dir.exists() { + if let Err(err) = self.fs.dir_create(dir) { + error!(?err, ?dir, "Failed to create server storage"); + return None; + } + } + let Ok(canon) = dir.canonicalize() else { + error!(?dir, "Failed to confirm server storage"); + return None; + }; + if let Err(err) = self.create_forge_data_directories(server_config, &canon) { + error!(?err, "Failure creating forge storage"); + return None; + } + Some(server_storage) + } } diff --git a/crates/server/src/lib.rs b/crates/server/src/lib.rs index 8a4003c..601b0ae 100644 --- a/crates/server/src/lib.rs +++ b/crates/server/src/lib.rs @@ -40,7 +40,6 @@ pub fn start( info!("Starting Server..."); let execution = async move { - //- let server = Server::new(fs.clone(), net.clone(), repo, sleep_duration).start(); server.do_send(FileUpdated);