From 855211f45859f287f5b33a9293c563081617cf85 Mon Sep 17 00:00:00 2001 From: Lynnesbian Date: Sat, 6 Nov 2021 01:10:20 +1000 Subject: [PATCH] clean up windows hidden file code --- .idea/fif.iml | 1 + Cargo.lock | 4 ++-- src/files.rs | 15 ++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.idea/fif.iml b/.idea/fif.iml index 7eca1fc..f58169f 100644 --- a/.idea/fif.iml +++ b/.idea/fif.iml @@ -4,6 +4,7 @@ + diff --git a/Cargo.lock b/Cargo.lock index cfb7dfe..9d32fa2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,9 +297,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.105" +version = "0.2.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013" +checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673" [[package]] name = "log" diff --git a/src/files.rs b/src/files.rs index 071212a..1c5df02 100644 --- a/src/files.rs +++ b/src/files.rs @@ -30,12 +30,13 @@ cfg_if! { if #[cfg(windows)] { /// Determines whether or not a file is hidden by checking its win32 file attributes. pub fn is_hidden(entry: &DirEntry) -> bool { - use std::os::windows::prelude::*; - std::fs::metadata(entry.path()) // try to get metadata for file - .map_or( - false, // if getting metadata/attributes fails, assume it's not hidden - |f| f.file_attributes() & 0x2 > 0, // flag for hidden - https://docs.microsoft.com/windows/win32/fileio/file-attribute-constants - ) + use std::os::windows::prelude::*; + const FILE_ATTRIBUTE_HIDDEN: u32 = 0x2; // http://docs.microsoft.com/windows/win32/fileio/file-attribute-constants + std::fs::metadata(entry.path()) // try to get metadata for file + .map_or( + false, // if getting metadata/attributes fails, assume it's not hidden + |f| f.file_attributes() & FILE_ATTRIBUTE_HIDDEN > 0, + ) } } else { /// Determines whether or not a file is hidden by checking for a leading full stop. @@ -158,7 +159,7 @@ pub fn scan_from_walkdir( chunk .iter() // iter over the chunk, which is a slice of DirEntry structs .map(|entry| scan_file(entry, canonical_paths)) - .collect::>() // TODO: is there a way to avoid having to collect here? + .collect::>() }).partition_map(|result| match result { Ok(f) => Either::Left(f), Err(e) => Either::Right(e),