mirror of
https://github.com/tobi/disktree.git
synced 2026-12-01 08:01:24 +00:00
scan: the hidden attribute hides an entry on Windows, as Explorer does
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
41328cdc67
commit
e1851c624b
@@ -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.
|
||||
|
||||
|
||||
@@ -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<Facts>;
|
||||
/// What a directory is, read before the walk enters it.
|
||||
fn directory(&self) -> io::Result<Directory>;
|
||||
/// 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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user