From b578a47cb5e337f269277bd8f4f7ae1ba37d2074 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 8 Jun 2025 08:56:09 +0100 Subject: [PATCH] Refactor are_file_paths_equivalent() --- src/archive/find.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/archive/find.rs b/src/archive/find.rs index 8b9a4b81..700a7c42 100644 --- a/src/archive/find.rs +++ b/src/archive/find.rs @@ -127,25 +127,15 @@ fn find_associated_archives_with_arbitrary_suffixes( #[cfg(windows)] fn are_file_paths_equivalent(lhs: &Path, rhs: &Path) -> bool { - use std::fs::File; - if lhs == rhs { return true; } - let Ok(lhs_file) = File::open(lhs) else { + let Some(lhs_info) = get_file_info(lhs) else { return false; }; - let Ok(rhs_file) = File::open(rhs) else { - return false; - }; - - let Some(lhs_info) = get_file_info(&lhs_file) else { - return false; - }; - - let Some(rhs_info) = get_file_info(&rhs_file) else { + let Some(rhs_info) = get_file_info(rhs) else { return false; }; @@ -155,10 +145,14 @@ fn are_file_paths_equivalent(lhs: &Path, rhs: &Path) -> bool { } #[cfg(windows)] -fn get_file_info(file: &std::fs::File) -> Option { +fn get_file_info(file_path: &Path) -> Option { use std::os::windows::io::AsRawHandle; use windows::Win32::{Foundation::HANDLE, Storage::FileSystem::GetFileInformationByHandle}; + let Ok(file) = std::fs::File::open(file_path) else { + return None; + }; + let mut info = BY_HANDLE_FILE_INFORMATION::default(); // SAFETY: This is safe because the file handles and the info struct pointers are all valid until this function exits.