[Fix] use working directory instead of executable directory

This commit is contained in:
Alois 2026-05-18 21:25:18 +02:00
commit 6c041fb278
4 changed files with 9 additions and 9 deletions

1
flake.lock generated
View file

@ -82,7 +82,6 @@
"locked": { "locked": {
"lastModified": 1778948017, "lastModified": 1778948017,
"narHash": "sha256-hqBYSZnPq7f/F2Z6nJK+6a8ITk6WRCcVBcNT0CR6SnM=", "narHash": "sha256-hqBYSZnPq7f/F2Z6nJK+6a8ITk6WRCcVBcNT0CR6SnM=",
"ref": "refs/heads/main",
"rev": "7e5d1953df8592a1feba0f390d205d0ef61a3119", "rev": "7e5d1953df8592a1feba0f390d205d0ef61a3119",
"revCount": 117, "revCount": 117,
"type": "git", "type": "git",

View file

@ -6,9 +6,14 @@ mod rho;
mod util; mod util;
use std::env; use std::env;
use std::path::PathBuf;
use dotenv::dotenv; use dotenv::dotenv;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
pub static WORKING_DIR: Lazy<PathBuf> = Lazy::new(|| {
std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."))
});
use rustls::crypto::aws_lc_rs::default_provider; use rustls::crypto::aws_lc_rs::default_provider;
use crate::{ use crate::{

View file

@ -1,6 +1,6 @@
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::{self, BufReader, Read}; use std::io::{self, BufReader, Read};
use std::path::{Path, PathBuf}; use std::path::Path;
use crate::log; use crate::log;
use crate::util::logger::PrintType; use crate::util::logger::PrintType;
@ -177,8 +177,5 @@ pub fn get_children(path: &str) -> Vec<String> {
} }
pub fn get_directory() -> String { pub fn get_directory() -> String {
std::env::current_dir() crate::WORKING_DIR.to_string_lossy().to_string()
.unwrap_or_else(|_| PathBuf::from("."))
.to_string_lossy()
.to_string()
} }

View file

@ -2,7 +2,6 @@ use std::{
collections::BTreeMap, collections::BTreeMap,
fs::{self, OpenOptions}, fs::{self, OpenOptions},
io::Write, io::Write,
path::Path,
sync::{OnceLock, mpsc}, sync::{OnceLock, mpsc},
thread, thread,
time::{SystemTime, UNIX_EPOCH}, time::{SystemTime, UNIX_EPOCH},
@ -39,8 +38,8 @@ pub fn startup() {
LOGGER.set(tx).expect("Logger already initialized"); LOGGER.set(tx).expect("Logger already initialized");
thread::spawn(move || { thread::spawn(move || {
let log_dir = Path::new("logs"); let log_dir = crate::WORKING_DIR.join("logs");
fs::create_dir_all(log_dir).expect("Failed to create log directory"); fs::create_dir_all(&log_dir).expect("Failed to create log directory");
let start_ts = SystemTime::now() let start_ts = SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)