From 7151b0397abd63dd86c5588d9f21c2b07507e847 Mon Sep 17 00:00:00 2001 From: Reactor Scram Date: Tue, 13 Aug 2024 17:39:52 -0500 Subject: [PATCH] fix(gui-client): delete crash dumps when deleting logs (#6281) This was a regression in a recent PR --- .../gui-client/src-tauri/src/client/logging.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/rust/gui-client/src-tauri/src/client/logging.rs b/rust/gui-client/src-tauri/src/client/logging.rs index fc1dfc005..f8b2385dc 100644 --- a/rust/gui-client/src-tauri/src/client/logging.rs +++ b/rust/gui-client/src-tauri/src/client/logging.rs @@ -167,19 +167,15 @@ fn choose_logs_to_delete(paths: &[PathBuf]) -> Vec<&Path> { paths .iter() - .filter(|path| { - let Some(stem) = path.file_stem() else { - return false; - }; - let Some(stem) = stem.to_str() else { - return false; - }; + .filter_map(|path| { + // Don't delete files if we can't parse their stems as UTF-8. + let stem = path.file_stem()?.to_str()?; if !stem.starts_with("connlib.") { - return false; + // Delete any non-log files like crash dumps. + return Some(path.as_path()); } - stem < most_recent_stem + (stem < most_recent_stem).then_some(path.as_path()) }) - .map(|x| x.as_path()) .collect() } @@ -344,6 +340,8 @@ mod tests { "/bogus/connlib.2024-08-06-14-21-13.log", "/bogus/connlib.2024-08-06-14-51-19.jsonl", "/bogus/connlib.2024-08-06-14-51-19.log", + "/bogus/crash.2024-07-22-21-16-20.dmp", + "/bogus/last_crash.dmp", ] .into_iter() .map(Path::new)