bug fixed with dependencies on deleted notes

This commit is contained in:
aaron-jack-manning 2022-09-14 20:37:36 +10:00
parent 182efe568a
commit 1cfd481484
2 changed files with 19 additions and 6 deletions

View File

@ -48,15 +48,21 @@ impl Graph {
}
}
pub fn remove_node(&mut self, node : Id) -> bool {
/// Returns a boolean indicating if the graph was changed (it contained the node) and a
/// set of all dependents on the removed node.
pub fn remove_node(&mut self, node : Id) -> (bool, HashSet<Id>) {
let mut dependents = HashSet::new();
if self.edges.remove(&node).is_some() {
for outgoing in self.edges.values_mut() {
outgoing.remove(&node);
for (&dependent, outgoing) in &mut self.edges {
if outgoing.remove(&node) {
dependents.insert(dependent);
}
}
true
(true, dependents)
}
else {
false
(false, dependents)
}
}

View File

@ -127,7 +127,14 @@ fn program() -> Result<(), error::Error> {
let task = tasks::Task::load(id, vault_folder, false)?;
let name = task.data.name.clone();
state.data.index.remove(task.data.name.clone(), task.data.id);
state.data.deps.remove_node(task.data.id);
// Removing the task from others which list it as a dependency.
if let (true, dependents) = state.data.deps.remove_node(task.data.id) {
for dependent in dependents {
let mut task = tasks::Task::load(dependent, vault_folder, false)?;
task.data.dependencies.remove(&id);
task.save()?;
}
}
task.delete()?;
println!("Deleted task {} (ID: {})", format::task(&name), format::id(id));