bug fixed with dependencies on deleted notes
This commit is contained in:
parent
182efe568a
commit
1cfd481484
16
src/graph.rs
16
src/graph.rs
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user