[Fix] use working directory instead of executable directory
This commit is contained in:
parent
e2e38b6fbb
commit
8331538bfe
3 changed files with 18 additions and 8 deletions
|
|
@ -10,12 +10,14 @@ use crate::sql::sql::print_users;
|
|||
use crate::transport::omikron_connection;
|
||||
use crate::util::crypto_helper::load_public_key;
|
||||
use crate::util::crypto_helper::load_secret_key;
|
||||
use crate::util::file_util::get_directory;
|
||||
use crate::util::logger::PrintType;
|
||||
use crate::util::logger::startup;
|
||||
use dotenv::dotenv;
|
||||
use dotenv::from_path;
|
||||
use once_cell::sync::Lazy;
|
||||
use rustls::crypto::aws_lc_rs::default_provider;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
|
||||
static PRIVATE_KEY: Lazy<String> = Lazy::new(|| env::var("PRIVATE_KEY").unwrap());
|
||||
pub fn get_private_key() -> x448::Secret {
|
||||
|
|
@ -32,7 +34,7 @@ async fn main() {
|
|||
println!("Error loading Provider");
|
||||
return;
|
||||
}
|
||||
dotenv().ok();
|
||||
let _ = from_path(Path::new(&get_directory()).join(".env"));
|
||||
startup();
|
||||
log_in!("Incoming messages");
|
||||
log_out!("Outgoing messages");
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use once_cell::sync::Lazy;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{self, BufReader, Read};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
|
@ -7,6 +8,10 @@ use zip::ZipArchive;
|
|||
|
||||
use crate::log;
|
||||
|
||||
static WORKING_DIR: Lazy<PathBuf> = Lazy::new(|| {
|
||||
std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."))
|
||||
});
|
||||
|
||||
pub fn delete_file(path: &str, name: &str) -> bool {
|
||||
let dir = Path::new(&get_directory()).join(path);
|
||||
let file = dir.join(name);
|
||||
|
|
@ -163,10 +168,11 @@ pub fn get_children(path: &str) -> Vec<String> {
|
|||
}
|
||||
|
||||
pub fn get_directory() -> String {
|
||||
std::env::current_dir()
|
||||
.unwrap_or_else(|_| PathBuf::from("."))
|
||||
.to_string_lossy()
|
||||
.to_string()
|
||||
WORKING_DIR.to_string_lossy().to_string()
|
||||
}
|
||||
|
||||
pub fn working_dir() -> &'static Path {
|
||||
&WORKING_DIR
|
||||
}
|
||||
|
||||
// Helper to download the zip file content to a file on disk
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ use std::{
|
|||
use ansi_term::Color;
|
||||
use ttp_core::{CommunicationValue, DataTypes, DataValue};
|
||||
|
||||
use crate::util::file_util::get_directory;
|
||||
|
||||
static LOGGER: OnceLock<mpsc::Sender<LogMessage>> = OnceLock::new();
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
|
|
@ -38,8 +40,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 = Path::new(&get_directory()).join("logs");
|
||||
fs::create_dir_all(&log_dir).expect("Failed to create log directory");
|
||||
|
||||
let start_ts = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
|
|
|
|||
Loading…
Reference in a new issue