fix: replace hardcoded paths in watcher.rs (A-4.2 P3)
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 ✅
This commit is contained in:
+10
-7
@@ -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<String> {
|
||||
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<String> {
|
||||
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 =
|
||||
|
||||
Reference in New Issue
Block a user