diff --git a/flake.lock b/flake.lock index a5ac9b9..360f62c 100644 --- a/flake.lock +++ b/flake.lock @@ -82,7 +82,6 @@ "locked": { "lastModified": 1778948017, "narHash": "sha256-hqBYSZnPq7f/F2Z6nJK+6a8ITk6WRCcVBcNT0CR6SnM=", - "ref": "refs/heads/main", "rev": "7e5d1953df8592a1feba0f390d205d0ef61a3119", "revCount": 117, "type": "git", diff --git a/src/main.rs b/src/main.rs index f10b39f..c14b222 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,14 @@ mod rho; mod util; use std::env; +use std::path::PathBuf; use dotenv::dotenv; use once_cell::sync::Lazy; + +pub static WORKING_DIR: Lazy = Lazy::new(|| { + std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")) +}); use rustls::crypto::aws_lc_rs::default_provider; use crate::{ diff --git a/src/util/file_util.rs b/src/util/file_util.rs index 344d967..e1a139a 100644 --- a/src/util/file_util.rs +++ b/src/util/file_util.rs @@ -1,6 +1,6 @@ use std::fs::{self, File}; use std::io::{self, BufReader, Read}; -use std::path::{Path, PathBuf}; +use std::path::Path; use crate::log; use crate::util::logger::PrintType; @@ -177,8 +177,5 @@ pub fn get_children(path: &str) -> Vec { } pub fn get_directory() -> String { - std::env::current_dir() - .unwrap_or_else(|_| PathBuf::from(".")) - .to_string_lossy() - .to_string() + crate::WORKING_DIR.to_string_lossy().to_string() } diff --git a/src/util/logger.rs b/src/util/logger.rs index 42188f4..66f3e8c 100644 --- a/src/util/logger.rs +++ b/src/util/logger.rs @@ -2,7 +2,6 @@ use std::{ collections::BTreeMap, fs::{self, OpenOptions}, io::Write, - path::Path, sync::{OnceLock, mpsc}, thread, time::{SystemTime, UNIX_EPOCH}, @@ -39,8 +38,8 @@ pub fn startup() { LOGGER.set(tx).expect("Logger already initialized"); thread::spawn(move || { - let log_dir = Path::new("logs"); - fs::create_dir_all(log_dir).expect("Failed to create log directory"); + let log_dir = crate::WORKING_DIR.join("logs"); + fs::create_dir_all(&log_dir).expect("Failed to create log directory"); let start_ts = SystemTime::now() .duration_since(UNIX_EPOCH)