Delete a specific task and its associated directory. Removes the task from storage and deletes its working directory.
(&self, task_id: &str)
| 57 | /// |
| 58 | /// Removes the task from storage and deletes its working directory. |
| 59 | pub async fn delete_task(&self, task_id: &str) -> Result<(), String> { |
| 60 | // Get the task to find its directory |
| 61 | let task = self |
| 62 | .task_storage |
| 63 | .get_task(task_id) |
| 64 | .await |
| 65 | .map_err(|e| format!("Error getting task: {e}"))?; |
| 66 | |
| 67 | if task.is_none() { |
| 68 | return Err(format!("Task with ID '{task_id}' not found")); |
| 69 | } |
| 70 | |
| 71 | // Delete from storage first |
| 72 | self.task_storage |
| 73 | .delete_task(task_id) |
| 74 | .await |
| 75 | .map_err(|e| format!("Error deleting task from storage: {e}"))?; |
| 76 | |
| 77 | // Delete the task directory using the copied_repo_path |
| 78 | let task = task.unwrap(); |
| 79 | // The task directory is the parent of the copied repo path |
| 80 | if let Some(ref copied_repo_path) = task.copied_repo_path |
| 81 | && let Some(task_dir) = copied_repo_path.parent() |
| 82 | && crate::file_system::exists(task_dir).await.unwrap_or(false) |
| 83 | { |
| 84 | crate::file_system::remove_dir(task_dir) |
| 85 | .await |
| 86 | .map_err(|e| format!("Error deleting task directory: {e}"))?; |
| 87 | } |
| 88 | |
| 89 | Ok(()) |
| 90 | } |
| 91 | |
| 92 | /// Delete completed (and optionally failed) tasks that are not parents of active children. |
| 93 | /// |