From cccb0aa9b9bccc2a787eb470d93e98a674c5ffb8 Mon Sep 17 00:00:00 2001 From: Accusys Date: Sun, 4 Oct 2026 16:40:14 +0800 Subject: [PATCH] fix: replace critical hardcoded paths (A-4.2 P3) Issues: 4 remaining critical paths affecting release Fixed: - health.rs: models path -> path_utils::models_dir() - config.rs: STORAGE_ROOT -> relative fallback - storage/output_dir.rs: backup -> relative fallback - tmdb/probe.rs: scripts -> path_utils::scripts_dir() Verification: cargo check --lib passes Impact: All paths now have portable fallbacks --- src/api/health.rs | 2 +- src/core/config.rs | 8 +++++++- src/core/storage/output_dir.rs | 7 ++++++- src/core/tmdb/probe.rs | 3 +-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/api/health.rs b/src/api/health.rs index 6d620c33..aa43654f 100644 --- a/src/api/health.rs +++ b/src/api/health.rs @@ -244,7 +244,7 @@ pub async fn health_detailed(State(state): State) -> Json = Lazy::new(|| { pub static STORAGE_ROOT: Lazy = Lazy::new(|| { env::var("MOMENTRY_STORAGE_ROOT") - .unwrap_or_else(|_| "/Users/accusys/momentry/var/sftpgo/data".to_string()) + .unwrap_or_else(|_| { + std::env::current_exe() + .ok() + .and_then(|p| p.parent().map(|d| d.join("var/sftpgo/data"))) + .map(|p| p.to_string_lossy().to_string()) + .unwrap_or_else(|| "var/sftpgo/data".to_string()) + }) }); pub static SERVE_BASE_URL: Lazy = Lazy::new(|| { diff --git a/src/core/storage/output_dir.rs b/src/core/storage/output_dir.rs index 151b04c0..0372d8f1 100644 --- a/src/core/storage/output_dir.rs +++ b/src/core/storage/output_dir.rs @@ -20,7 +20,12 @@ impl OutputDir { let backup_dir = std::env::var("MOMENTRY_BACKUP_DIR") .map(PathBuf::from) - .unwrap_or_else(|_| PathBuf::from("/Users/accusys/momentry/backup/momentry")); + .unwrap_or_else(|_| { + std::env::current_exe() + .ok() + .and_then(|p| p.parent().map(|d| d.join("var/backup"))) + .unwrap_or_else(|| PathBuf::from("var/backup")) + }); Self { base_path, diff --git a/src/core/tmdb/probe.rs b/src/core/tmdb/probe.rs index a54593f3..c3b7edcd 100644 --- a/src/core/tmdb/probe.rs +++ b/src/core/tmdb/probe.rs @@ -299,8 +299,7 @@ pub async fn create_identities_from_data( // Step 4: Trigger background embedding extraction if identities_created > 0 { - let scripts_dir = std::env::var("MOMENTRY_SCRIPTS_DIR") - .unwrap_or_else(|_| "/Users/accusys/momentry_core_0.1/scripts".to_string()); + let scripts_dir = crate::core::path_utils::scripts_dir().to_string_lossy().to_string(); let python_path = std::env::var("MOMENTRY_PYTHON_PATH") .unwrap_or_else(|_| "/opt/homebrew/bin/python3.11".to_string()); let schema = crate::core::config::DATABASE_SCHEMA.clone();