MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / delete_task

Method delete_task

src/task_manager.rs:59–90  ·  view source on GitHub ↗

Delete a specific task and its associated directory. Removes the task from storage and deletes its working directory.

(&self, task_id: &str)

Source from the content-addressed store, hash-verified

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 ///

Callers 2

clean_tasksMethod · 0.45
test_delete_taskFunction · 0.45

Calls 3

existsFunction · 0.85
remove_dirFunction · 0.85
get_taskMethod · 0.80

Tested by 1

test_delete_taskFunction · 0.36