From ff97dd148476a5cb5f5bf72743458f7cf8de37e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C3=85kesson?= Date: Sun, 15 Mar 2026 10:54:00 +0100 Subject: [PATCH] refactor(core): flatten using early escapes --- core/src/scanner.rs | 57 ++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/core/src/scanner.rs b/core/src/scanner.rs index 99f4b1e..c8868eb 100644 --- a/core/src/scanner.rs +++ b/core/src/scanner.rs @@ -22,38 +22,31 @@ pub fn find_broken_symlinks(path: &Path, ignore: &[String]) -> Vec { - let file_type = dir_entry.file_type(); - if file_type.is_symlink() { - let link_path = dir_entry.path().to_path_buf(); - match fs::read_link(&link_path) { - Ok(target_path) => { - // This resolves relative targets against the symlinks parent - let resolved: PathBuf = if target_path.is_relative() { - link_path - .parent() - .unwrap_or(Path::new(".")) - .join(&target_path) - } else { - target_path.clone() - }; - if !resolved.exists() { - broken_symlinks.push(BrokenSymlink { - link: link_path, - target: target_path, - }); - } - } - Err(_) => { - // An unreadable link isn't really actionable - // So we can just continue - continue; - } - } - } - } - Err(_) => continue, + let Ok(dir_entry) = entry else { + continue; + }; + let file_type = dir_entry.file_type(); + if !file_type.is_symlink() { + continue; + } + let link_path = dir_entry.path().to_path_buf(); + let Ok(target_path) = fs::read_link(&link_path) else { + continue; + }; + // This resolves relative targets against the symlinks parent + let resolved: PathBuf = if target_path.is_relative() { + link_path + .parent() + .unwrap_or(Path::new(".")) + .join(&target_path) + } else { + target_path.clone() + }; + if !resolved.exists() { + broken_symlinks.push(BrokenSymlink { + link: link_path, + target: target_path, + }); } }