From 122532c2f7c66f03e0820e423e7e349c044e87ae Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Mon, 23 Feb 2026 18:29:27 +0100 Subject: [PATCH] fix: stabilize process targeting with search/pinning and fix targeted report data isolation --- src-tauri/src/main.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 9b667da..220af3c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -409,22 +409,26 @@ fn generate_report(start_time: DateTime, snapshots: Vec, mode: Pr // Targeted mode: Return only the target root(s) and their hierarchy let mut targeted_roots = Vec::new(); if let Some(tpid) = target_pid { - // Find target or its closest surviving ancestor/child in the tree - // Actually final_roots already contains the full tree. - // We want only the root that contains our target PID. - fn find_target_node(roots: &mut Vec, tpid: u32) -> Option { - for i in 0..roots.len() { - if roots[i].pid == tpid { - return Some(roots.remove(i)); - } - if let Some(found) = find_target_node(&mut roots[i].children, tpid) { - return Some(found); + fn extract_target(nodes: Vec, tpid: u32) -> (Vec, Option) { + let mut remaining = Vec::new(); + let mut found = None; + for mut node in nodes { + if node.pid == tpid { + found = Some(node); + } else { + let (new_children, sub_found) = extract_target(node.children, tpid); + node.children = new_children; + if let Some(f) = sub_found { + found = Some(f); + } + remaining.push(node); } } - None + (remaining, found) } - if let Some(target_tree) = find_target_node(&mut final_roots, tpid) { - targeted_roots.push(target_tree); + let (_, target_node) = extract_target(final_roots, tpid); + if let Some(t) = target_node { + targeted_roots.push(t); } }