From e1851c624b35464a1cafb98a3be320d5d2a1da2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobi=20L=C3=BCtke?= Date: Fri, 25 Sep 2026 16:19:45 +0000 Subject: [PATCH] scan: the hidden attribute hides an entry on Windows, as Explorer does Co-Authored-By: Claude Opus 5.5 (1M context) --- README.md | 4 +-- crates/disktree-core/src/scan.rs | 39 ++++++++++++++++++++++++++++- crates/disktree-core/src/windows.rs | 20 +++++++++------ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 54e5272..2476158 100644 --- a/README.md +++ b/README.md @@ -278,8 +278,8 @@ The same program, with Windows' answers to the questions above: Information, Recovery, Boot), and any folder holding your profile, such as `C:\Users`. Names compare without regard to case, as Windows compares them. -- **Hidden** still means a name starting with a dot; the hidden attribute is - not consulted, so `-H` does not drop `AppData`. +- **Hidden** means a name starting with a dot, or the hidden attribute, so + `-H` drops `AppData` as Explorer hides it. - **The theme** follows Windows' light or dark setting, since there is no Omarchy theme to follow. It does on macOS too, and on GNOME and KDE. diff --git a/crates/disktree-core/src/scan.rs b/crates/disktree-core/src/scan.rs index 2dd0ed7..f9abac6 100644 --- a/crates/disktree-core/src/scan.rs +++ b/crates/disktree-core/src/scan.rs @@ -293,7 +293,9 @@ impl WalkContext { }; let name = entry.display_name(); - if !self.options.include_hidden && name.starts_with('.') { + if !self.options.include_hidden + && (name.starts_with('.') || entry.hidden()) + { return Classified::Skipped; } @@ -461,6 +463,12 @@ trait Listed { fn facts(&self, apparent_size: bool) -> io::Result; /// What a directory is, read before the walk enters it. fn directory(&self) -> io::Result; + /// Hidden by an attribute rather than by a leading dot: on Windows, + /// where the listing carries it, so `AppData` is hidden as Explorer + /// hides it. macOS's `UF_HIDDEN` would cost a stat per entry. + fn hidden(&self) -> bool { + false + } } /// Whether [`Directory::evicted`] can ever be true here, so a platform that @@ -584,6 +592,10 @@ impl Listed for crate::windows::Entry { evicted: self.evicted(), }) } + + fn hidden(&self) -> bool { + self.hidden() + } } /// List a directory the way [`Listed`] describes. @@ -1083,6 +1095,31 @@ mod tests { assert_eq!(without.bytes, 100); } + /// Explorer's hidden attribute counts as hidden, as `AppData` has it. + #[cfg(windows)] + #[test] + fn the_hidden_attribute_hides_an_entry_on_windows() { + let temp = TempDir::new().expect("tempdir"); + let root = temp.path(); + write(root, "AppData/blob.bin", 900); + write(root, "visible.bin", 100); + let marked = std::process::Command::new("attrib") + .arg("+h") + .arg(root.join("AppData")) + .status() + .is_ok_and(|status| status.success()); + assert!(marked, "attrib +h"); + + let without = scan_dir( + root, + &ScanOptions { + include_hidden: false, + ..options() + }, + ); + assert_eq!(without.bytes, 100); + } + /// A link to a directory: a symbolic link on Unix, a junction on /// Windows, which needs no privilege to make. `false` if it could not be /// made. diff --git a/crates/disktree-core/src/windows.rs b/crates/disktree-core/src/windows.rs index 9ec88d9..9e9468d 100644 --- a/crates/disktree-core/src/windows.rs +++ b/crates/disktree-core/src/windows.rs @@ -30,13 +30,13 @@ use windows_sys::Win32::Foundation::{ ERROR_NO_MORE_FILES, ERROR_NOT_SUPPORTED, INVALID_HANDLE_VALUE, }; use windows_sys::Win32::Storage::FileSystem::{ - FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS, - FILE_ATTRIBUTE_RECALL_ON_OPEN, FILE_ATTRIBUTE_REPARSE_POINT, - FILE_FLAG_BACKUP_SEMANTICS, FILE_ID_EXTD_DIR_INFO, FILE_LIST_DIRECTORY, - FILE_READ_ATTRIBUTES, FileIdExtdDirectoryInfo, FindFirstVolumeW, - FindNextVolumeW, FindVolumeClose, GetDiskFreeSpaceExW, - GetFileInformationByHandleEx, GetVolumePathNameW, - GetVolumePathNamesForVolumeNameW, SYNCHRONIZE, + FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_HIDDEN, + FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS, FILE_ATTRIBUTE_RECALL_ON_OPEN, + FILE_ATTRIBUTE_REPARSE_POINT, FILE_FLAG_BACKUP_SEMANTICS, + FILE_ID_EXTD_DIR_INFO, FILE_LIST_DIRECTORY, FILE_READ_ATTRIBUTES, + FileIdExtdDirectoryInfo, FindFirstVolumeW, FindNextVolumeW, + FindVolumeClose, GetDiskFreeSpaceExW, GetFileInformationByHandleEx, + GetVolumePathNameW, GetVolumePathNamesForVolumeNameW, SYNCHRONIZE, }; use crate::space::SpaceInfo; @@ -116,6 +116,12 @@ impl Entry { self.modified } + /// Whether Explorer hides this: `FILE_ATTRIBUTE_HIDDEN`, as on + /// `AppData` and `$Recycle.Bin`. + pub const fn hidden(&self) -> bool { + self.attributes & FILE_ATTRIBUTE_HIDDEN != 0 + } + /// Whether this is a directory the cloud files provider holds and the /// disk does not: see [`EVICTED`]. pub const fn evicted(&self) -> bool {