From c6eba691a81defeb24404e7f5d293b36f2d85975 Mon Sep 17 00:00:00 2001 From: icsboyx Date: Tue, 6 Jan 2026 14:34:31 +0100 Subject: [PATCH] Refactor asset and logging directory creation for improved clarity --- src/data_mgt.rs | 3 --- src/logs.rs | 7 +------ src/main.rs | 5 ++++- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/data_mgt.rs b/src/data_mgt.rs index 11e1370..c393c28 100644 --- a/src/data_mgt.rs +++ b/src/data_mgt.rs @@ -1,5 +1,3 @@ -use std::fs; - use anyhow::Result; use chrono::{Duration, Utc}; use serde::{Deserialize, Serialize}; @@ -52,7 +50,6 @@ impl Asset { } pub fn save(&self) -> Result { - let _ = fs::create_dir_all(DATA_STORAGE); let id = self.id.clone(); let path = format!("{}{}", DATA_STORAGE, self.id); std::fs::create_dir_all(DATA_STORAGE)?; diff --git a/src/logs.rs b/src/logs.rs index 68f0cbe..0595516 100644 --- a/src/logs.rs +++ b/src/logs.rs @@ -1,8 +1,4 @@ -use std::{ - fs::{self, OpenOptions}, - io::Write, - time::Instant, -}; +use std::{fs::OpenOptions, io::Write, time::Instant}; use actix_web::HttpRequest; @@ -12,7 +8,6 @@ pub fn log_to_file(req: &HttpRequest, start: Instant) { let delta = start.elapsed().as_nanos(); println!("Request processed in {} ns", delta); let duration_ms = delta as f64 / 1000_000.0; - let _ = fs::create_dir_all(LOG_DIR); let log_path = LOG_DIR.to_string() + "access.log"; diff --git a/src/main.rs b/src/main.rs index 126e2c0..b3bbe75 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use actix_web::{ web::{self}, }; use serde_json::Value; -use std::path::PathBuf; +use std::{fs, path::PathBuf}; pub static BIND_ADDR: &str = "0.0.0.0"; pub static BIND_PORT: u16 = 80; @@ -56,6 +56,9 @@ async fn catch_all(req: HttpRequest, _payload: Option>) -> acti #[actix_web::main] async fn main() -> std::io::Result<()> { + let _ = fs::create_dir_all(DATA_STORAGE); + let _ = fs::create_dir_all(LOG_DIR); + println!("Starting server at http://{}:{}/", BIND_ADDR, BIND_PORT); tokio::spawn(async { let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(60));