From 135dfb06d525baf44b22fe6299e1224a1a2bf828 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Sun, 12 Apr 2026 16:43:29 -0300 Subject: [PATCH] fix: delete orphaned .ast files when .bas is removed from MinIO When a .bas file is deleted from the bucket, DriveMonitor now: - Deletes the corresponding .ast compiled file - Deletes .bas, .mcp.json, .tool.json files from work directory - Removes the path from file_states tracking This prevents stale compiled files from accumulating in production. --- src/drive/drive_monitor/mod.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/drive/drive_monitor/mod.rs b/src/drive/drive_monitor/mod.rs index bd143108..6f37c0eb 100644 --- a/src/drive/drive_monitor/mod.rs +++ b/src/drive/drive_monitor/mod.rs @@ -581,13 +581,42 @@ impl DriveMonitor { // Now acquire write lock to merge current_files into file_states let mut file_states = self.file_states.write().await; - // Remove files that no longer exist + // Remove files that no longer exist (deleted from MinIO) let previous_paths: Vec = file_states .keys() .cloned() .collect(); for path in previous_paths { if !current_files.contains_key(&path) { + // Delete the compiled .ast file from disk + let bot_name = self + .bucket_name + .strip_suffix(".gbai") + .unwrap_or(&self.bucket_name); + let ast_path = self.work_root + .join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name)) + .join(PathBuf::from(&path).file_name().unwrap_or_default().to_str().unwrap_or("")) + .with_extension("ast"); + + if ast_path.exists() { + if let Err(e) = std::fs::remove_file(&ast_path) { + warn!("Failed to delete orphaned .ast file {}: {}", ast_path.display(), e); + } else { + info!("Deleted orphaned .ast file: {}", ast_path.display()); + } + } + + // Also delete .bas, .mcp.json, .tool.json files + let bas_path = ast_path.with_extension("bas"); + let mcp_path = ast_path.with_extension("mcp.json"); + let tool_path = ast_path.with_extension("tool.json"); + + for file_to_delete in [&bas_path, &mcp_path, &tool_path] { + if file_to_delete.exists() { + let _ = std::fs::remove_file(file_to_delete); + } + } + file_states.remove(&path); } }