Skip to content

Commit 16385cb

Browse files
committed
file: add is_hidden predicate
This adds a convenience routine for checking whether file information has the hidden attribute set. This was motivated by this bug report against ripgrep: BurntSushi/ripgrep#1154
1 parent 4db516f commit 16385cb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ features = [
2323
"winbase",
2424
"wincon",
2525
"winerror",
26+
"winnt",
2627
]

src/file.rs

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use winapi::um::fileapi::{
88
BY_HANDLE_FILE_INFORMATION,
99
GetFileInformationByHandle, GetFileType,
1010
};
11+
use winapi::um::winnt;
1112

1213
use AsHandleRef;
1314

@@ -49,6 +50,12 @@ pub fn typ<H: AsHandleRef>(h: H) -> io::Result<Type> {
4950
}
5051
}
5152

53+
/// Returns true if and only if the given file attributes contain the
54+
/// `FILE_ATTRIBUTE_HIDDEN` attribute.
55+
pub fn is_hidden(file_attributes: u64) -> bool {
56+
file_attributes & (winnt::FILE_ATTRIBUTE_HIDDEN as u64) > 0
57+
}
58+
5259
/// Represents file information such as creation time, file size, etc.
5360
///
5461
/// This wraps a [`BY_HANDLE_FILE_INFORMATION`].
@@ -65,6 +72,12 @@ impl Information {
6572
self.0.dwFileAttributes as u64
6673
}
6774

75+
/// Returns true if and only if this file information has the
76+
/// `FILE_ATTRIBUTE_HIDDEN` attribute.
77+
pub fn is_hidden(&self) -> bool {
78+
is_hidden(self.file_attributes())
79+
}
80+
6881
/// Return the creation time, if one exists.
6982
///
7083
/// This corresponds to `ftCreationTime`.

0 commit comments

Comments
 (0)