clean up windows hidden file code

This commit is contained in:
Lynne Megido 2021-11-06 01:10:20 +10:00
parent 5df8545906
commit 855211f458
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
3 changed files with 11 additions and 9 deletions

View File

@ -4,6 +4,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/target" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" /> <excludeFolder url="file://$MODULE_DIR$/target" />
<excludeFolder url="file://$MODULE_DIR$/imgs" /> <excludeFolder url="file://$MODULE_DIR$/imgs" />
<excludeFolder url="file://$MODULE_DIR$/old" /> <excludeFolder url="file://$MODULE_DIR$/old" />

4
Cargo.lock generated
View File

@ -297,9 +297,9 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.105" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013" checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673"
[[package]] [[package]]
name = "log" name = "log"

View File

@ -30,12 +30,13 @@ cfg_if! {
if #[cfg(windows)] { if #[cfg(windows)] {
/// Determines whether or not a file is hidden by checking its win32 file attributes. /// Determines whether or not a file is hidden by checking its win32 file attributes.
pub fn is_hidden(entry: &DirEntry) -> bool { pub fn is_hidden(entry: &DirEntry) -> bool {
use std::os::windows::prelude::*; use std::os::windows::prelude::*;
std::fs::metadata(entry.path()) // try to get metadata for file const FILE_ATTRIBUTE_HIDDEN: u32 = 0x2; // http://docs.microsoft.com/windows/win32/fileio/file-attribute-constants
.map_or( std::fs::metadata(entry.path()) // try to get metadata for file
false, // if getting metadata/attributes fails, assume it's not hidden .map_or(
|f| f.file_attributes() & 0x2 > 0, // flag for hidden - https://docs.microsoft.com/windows/win32/fileio/file-attribute-constants false, // if getting metadata/attributes fails, assume it's not hidden
) |f| f.file_attributes() & FILE_ATTRIBUTE_HIDDEN > 0,
)
} }
} else { } else {
/// Determines whether or not a file is hidden by checking for a leading full stop. /// 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 chunk
.iter() // iter over the chunk, which is a slice of DirEntry structs .iter() // iter over the chunk, which is a slice of DirEntry structs
.map(|entry| scan_file(entry, canonical_paths)) .map(|entry| scan_file(entry, canonical_paths))
.collect::<Vec<_>>() // TODO: is there a way to avoid having to collect here? .collect::<Vec<_>>()
}).partition_map(|result| match result { }).partition_map(|result| match result {
Ok(f) => Either::Left(f), Ok(f) => Either::Left(f),
Err(e) => Either::Right(e), Err(e) => Either::Right(e),