From c55f664e47baebdb3dd5ccfc340ee53e5aeffe01 Mon Sep 17 00:00:00 2001 From: Accusys Date: Sun, 4 Oct 2026 16:27:44 +0800 Subject: [PATCH] fix: replace hardcoded paths in watcher.rs (A-4.2 P3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issues: 4 hardcoded fallback paths - default_dir: /Users/accusys/momentry/var/sftpgo/data/demo - 2× output_dir: /Users/accusys/momentry/output - scripts_dir: /Users/accusys/momentry_core_0.1/scripts Solution: Use config constants and relative paths - MOMENTRY_SFTP_ROOT or relative fallback - config::OUTPUT_DIR for output - path_utils::scripts_dir() for scripts Verification: cargo check --lib passes, 0 hardcoded paths Progress: admin_config.rs ✅, files.rs ✅, watcher.rs ✅ --- src/watcher/watcher.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/watcher/watcher.rs b/src/watcher/watcher.rs index 0163d05f..ebc5e88b 100644 --- a/src/watcher/watcher.rs +++ b/src/watcher/watcher.rs @@ -14,7 +14,13 @@ pub struct WatcherConfig { impl Default for WatcherConfig { fn default() -> Self { let default_dir = std::env::var("MOMENTRY_SFTP_ROOT") - .unwrap_or_else(|_| "/Users/accusys/momentry/var/sftpgo/data/demo/".to_string()); + .unwrap_or_else(|_| { + std::env::current_exe() + .ok() + .and_then(|p| p.parent().map(|d| d.join("var/sftpgo/data/demo"))) + .map(|p| p.to_string_lossy().to_string()) + .unwrap_or_else(|| "var/sftpgo/data/demo".to_string()) + }); Self { directories: vec![default_dir], poll_interval_ms: 60000, @@ -92,8 +98,7 @@ async fn auto_register_file(file_path: &str) { None => return, }; - let output_dir = std::env::var("MOMENTRY_OUTPUT_DIR") - .unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string()); + let output_dir = crate::core::config::OUTPUT_DIR.to_string(); let pre_path = std::path::PathBuf::from(&output_dir).join(format!("{}.pre.json", file_uuid)); let pre_content = match std::fs::read_to_string(&pre_path) { Ok(c) => c, @@ -206,8 +211,7 @@ pub async fn pre_process_file(file_path: &str) -> Option { let canonical_str = canonical.to_string_lossy().to_string(); let filename = path.file_name()?.to_string_lossy().to_string(); - let output_dir = std::env::var("MOMENTRY_OUTPUT_DIR") - .unwrap_or_else(|_| "/Users/accusys/momentry/output".to_string()); + let output_dir = crate::core::config::OUTPUT_DIR.to_string(); let birthday = std::fs::metadata(&path) .ok() @@ -238,8 +242,7 @@ pub async fn pre_process_file(file_path: &str) -> Option { let content_hash = crate::core::storage::content_hash::compute_sha256(&path).unwrap_or_default(); - 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 probe_json =