Removed IS_DEV and use is_dev from environment & simplified base path handling

This commit is contained in:
Thorsten Sommer 2026-03-14 11:21:10 +01:00
parent e3b65091b7
commit 8045bfd1f8
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 17 additions and 28 deletions

View File

@ -115,8 +115,8 @@ pub fn start_tauri() {
start_dotnet_server();
}
cleanup_qdrant(is_dev());
start_qdrant_server(app.path_resolver(), is_dev());
cleanup_qdrant();
start_qdrant_server(app.path_resolver());
info!(Source = "Bootloader Tauri"; "Reconfigure the file logger to use the app data directory {data_path:?}");
switch_to_file_logging(data_path).map_err(|e| error!("Failed to switch logging to file: {e}")).unwrap();
@ -1067,4 +1067,4 @@ fn set_pdfium_path(path_resolver: PathResolver) {
let pdfium_source_path = pdfium_source_path.unwrap();
let pdfium_source_path = pdfium_source_path.to_str().unwrap().to_string();
*PDFIUM_LIB_PATH.lock().unwrap() = Some(pdfium_source_path.clone());
}
}

View File

@ -12,10 +12,9 @@ use rocket::serde::json::Json;
use rocket::serde::Serialize;
use tauri::api::process::{Command, CommandChild, CommandEvent};
use crate::api_token::{APIToken};
use crate::environment::DATA_DIRECTORY;
use crate::environment::{is_dev, DATA_DIRECTORY};
use crate::certificate_factory::generate_certificate;
use std::path::PathBuf;
use once_cell::race::OnceBool;
use tauri::PathResolver;
use tempfile::{TempDir, Builder};
use crate::stale_process_cleanup::{kill_stale_process, log_potential_stale_process};
@ -41,11 +40,16 @@ static API_TOKEN: Lazy<APIToken> = Lazy::new(|| {
static TMPDIR: Lazy<Mutex<Option<TempDir>>> = Lazy::new(|| Mutex::new(None));
static IS_DEV: OnceBool = OnceBool::new();
const PID_FILE_NAME: &str = "qdrant.pid";
const SIDECAR_TYPE:SidecarType = SidecarType::Qdrant;
fn qdrant_base_path() -> PathBuf {
let qdrant_directory = if is_dev() { "qdrant_test" } else { "qdrant" };
Path::new(DATA_DIRECTORY.get().unwrap())
.join("databases")
.join(qdrant_directory)
}
#[derive(Serialize)]
pub struct ProvideQdrantInfo {
path: String,
@ -58,11 +62,7 @@ pub struct ProvideQdrantInfo {
#[get("/system/qdrant/info")]
pub fn qdrant_port(_token: APIToken) -> Json<ProvideQdrantInfo> {
Json(ProvideQdrantInfo {
path: if IS_DEV.get().unwrap(){
Path::new(DATA_DIRECTORY.get().unwrap()).join("databases").join("qdrant_test").to_str().unwrap().to_string()
}else{
Path::new(DATA_DIRECTORY.get().unwrap()).join("databases").join("qdrant").to_str().unwrap().to_string()
},
path: qdrant_base_path().to_str().unwrap().to_string(),
port_http: *QDRANT_SERVER_PORT_HTTP,
port_grpc: *QDRANT_SERVER_PORT_GRPC,
fingerprint: CERTIFICATE_FINGERPRINT.get().expect("Certificate fingerprint not available").to_string(),
@ -71,15 +71,8 @@ pub fn qdrant_port(_token: APIToken) -> Json<ProvideQdrantInfo> {
}
/// Starts the Qdrant server in a separate process.
pub fn start_qdrant_server(path_resolver: PathResolver, is_dev:bool){
IS_DEV.set(is_dev).expect("Could not set the is_dev flag.");
let base_path = DATA_DIRECTORY.get().unwrap();
let path = if IS_DEV.get().unwrap() {
Path::new(base_path).join("databases").join("qdrant_test")
}else{
Path::new(base_path).join("databases").join("qdrant")
};
pub fn start_qdrant_server(path_resolver: PathResolver){
let path = qdrant_base_path();
if !path.exists() {
if let Err(e) = fs::create_dir_all(&path){
error!(Source="Qdrant"; "The required directory to host the Qdrant database could not be created: {}", e);
@ -160,7 +153,7 @@ pub fn stop_qdrant_server() {
}
drop_tmpdir();
cleanup_qdrant(IS_DEV.get().unwrap());
cleanup_qdrant();
}
/// Create a temporary directory with TLS relevant files
@ -201,12 +194,8 @@ pub fn drop_tmpdir() {
}
/// Remove old Pid files and kill the corresponding processes
pub fn cleanup_qdrant(is_dev:bool) {
let path = if is_dev {
Path::new(DATA_DIRECTORY.get().unwrap()).join("databases").join("qdrant_test")
}else{
Path::new(DATA_DIRECTORY.get().unwrap()).join("databases").join("qdrant")
};
pub fn cleanup_qdrant() {
let path = qdrant_base_path();
let pid_path = path.join(PID_FILE_NAME);
if let Err(e) = kill_stale_process(pid_path, SIDECAR_TYPE) {
warn!(Source = "Qdrant"; "Error during the cleanup of Qdrant: {}", e);