check windows hidden file attribute

This commit is contained in:
Icxolu 2022-11-06 22:30:00 +01:00 committed by Abin Simon
parent c1c8958fd0
commit 62addc53e6
2 changed files with 37 additions and 1 deletions

View file

@ -109,7 +109,14 @@ impl Meta {
continue;
}
if flags.display == Display::VisibleOnly && name.to_string_lossy().starts_with('.') {
#[cfg(windows)]
let is_hidden =
name.to_string_lossy().starts_with('.') || windows_utils::is_path_hidden(&path);
#[cfg(not(windows))]
let is_hidden = name.to_string_lossy().starts_with('.');
// TODO: skip windows hidded
if flags.display == Display::VisibleOnly && is_hidden {
continue;
}

View file

@ -303,6 +303,35 @@ fn buf_from_os(os: &OsStr) -> Vec<u16> {
buf
}
/// Checks wether the given [`FILE_FLAGS_AND_ATTRIBUTES`] are set for the given
/// [`Path`]
///
/// [`FILE_FLAGS_AND_ATTRIBUTES`]: windows::Win32::Storage::FileSystem::FILE_FLAGS_AND_ATTRIBUTES
#[inline]
fn has_path_attribute(
path: &Path,
flags: windows::Win32::Storage::FileSystem::FILE_FLAGS_AND_ATTRIBUTES,
) -> bool {
let windows_path = buf_from_os(path.as_os_str());
let file_attributes = unsafe {
windows::Win32::Storage::FileSystem::GetFileAttributesW(windows::core::PCWSTR(
windows_path.as_ptr(),
))
};
file_attributes & flags.0 > 0
}
/// Checks whether the windows [`hidden`] attribute is set for the given
/// [`Path`]
///
/// [`hidden`]: windows::Win32::Storage::FileSystem::FILE_ATTRIBUTE_HIDDEN
pub fn is_path_hidden(path: &Path) -> bool {
has_path_attribute(
path,
windows::Win32::Storage::FileSystem::FILE_ATTRIBUTE_HIDDEN,
)
}
#[cfg(test)]
mod test {
use super::*;