Walking from / with O_NOFOLLOW refused every path under /var and /tmp
on macOS, which are links. Open the root as named and refuse links only
between it and the target, as the plan does. Also two tests that assumed
Unix now run or skip on Windows.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Windows strips trailing dots and spaces and maps NUL/COM1 to devices,
so a scanned `C:\Users.` would have removed `C:\Users`. Refused.
- The trash (everywhere) and removal on Windows follow a link on the way
to a target out of the scanned root. The real parent is compared with
the real root, in the plan and again on the worker.
- The home directory is also matched by its canonical path, so a link
such as /home -> /data/home no longer hides it from 'contains home'.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Permanent deletion opened its target by full path, following any
symlink on the way down. A directory swapped for a link after the scan
(a shared /tmp, say) redirected the removal: `/tmp/d/x` marked, `d`
made a link to `~`, and `~/x` went. The way down is now opened one
component at a time with O_NOFOLLOW (O_PATH on Linux), and the target
removed with unlinkat relative to its parent. The scanned root is
canonical, so a marked path never legitimately has a link on it.
The plan is judged against a mount table read on a background thread,
empty until the first read lands and up to two seconds old after. The
removal worker now reads it fresh and checks each target for a mount
point on it or inside it before touching anything. Permanent deletion
stopped at a mount boundary already; the trash did not.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
One set of removal guards for all three platforms: guard_key folds
macOS firmlinks and case, and now Windows case and verbatim prefixes,
so within/same from #14 become key comparisons. System trees are one
keyed list per platform.
Fixed while merging:
- plan() found home through $HOME, which Windows does not set, so every
home guard was off there; std::env::home_dir() instead.
- Scan: #14's Listed/Facts shape with #13's never-scanned paths,
dataless iCloud folders and track-only-shared-inodes; OneDrive
cloud-only folders are skipped the same way on Windows.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Removing a directory takes what is inside it. In a whole-disk scan on
Windows, C:\Users is an ordinary directory that passes every other
guard, and so is /home on a Linux install without a separate volume:
marking either would remove the home directory the guards are there to
protect.
disktree-core builds and measures on Windows. `windows.rs` holds what the
standard library does not give: a directory listing through
GetFileInformationByHandleEx with FileIdExtdDirectoryInfo, which carries
each entry's allocation and file id for a whole buffer of entries.
Opening every file for those two numbers made a walk of a home directory
of 1.3 million files seven times slower (65 s against 9 s); the listing
costs what FindNextFileW costs. Where a file system does not implement
it (a Samba share answers ERROR_INVALID_LEVEL), the walk falls back to
std's listing, with lengths.
- Disk usage is the NTFS allocation: whole clusters, less for a
compressed or sparse file, nothing for data kept in the file record.
- Hardlinks count once on NTFS, keyed by volume serial and file id. FAT
ids are documented as not unique and ReFS ids need all 128 bits, so
neither is used; there a hardlink counts once per name.
- Junctions and mounted folders are links, as std already treats them,
so the walk stays on one volume unless links are followed. The whole
disk is the drive the profile is on.
- Removal refuses Windows, Program Files, ProgramData and what Windows
keeps at the top of its drive, comparing names without case. A mounted
folder is a mount point. A link to a directory is removed with
RemoveDirectoryW, which leaves its target alone.
- Move to trash is the Recycle Bin, through the trash crate, which asks
the shell to warn before destroying anything it cannot recycle.
All unsafe code is in windows.rs, each block with the reason it is sound.
On Unix the walk reads the same metadata through the same calls.
disktree built and drew on macOS already, through GPUI's Metal backend,
but the Linux plumbing underneath did not carry over. This makes it work
well there, without unsafe code, and tightens removal safety for every
platform on the way.
Trash and removal
- On macOS always the system Trash, through NSFileManager (the trash
crate): the same move as Finder's, into the item's own disk's Trash.
gio/trash-put/XDG would put files in ~/.local/share/Trash, which Finder
never shows.
- Refuse a directory holding the home directory (/Users is on the same
volume as / on macOS) or a system tree (/opt holds /opt/homebrew); add
/System, /Library, /private, /opt/homebrew, /cores, /Network.
- Refuse a directory with a mount inside it; on macOS the mount list comes
from /sbin/mount, read on a background thread.
- Permanent deletion walks the tree itself and stops at a mount boundary,
like rm -rf --one-file-system (the walker is from #10).
- Guards see through /System/Volumes/Data spellings and, on macOS, case.
Scanning
- Skip /System/Volumes/Data when scanning /: it is /Users, /Applications
and the rest again under firmlinks, so / was counted twice.
- Whole disk (g, --disk) works: the disk root and device come from statfs.
- Never list cloud-only (dataless) iCloud/File Provider folders, which
would download them.
- Keep a file's identity only when it has more than one name.
App
- Explain unreadable items when Full Disk Access is missing, with a button
to the privacy settings.
- A menu bar: Open Folder… (⌘O), Show in Finder (o, ⌘⇧R), Rescan (⌘R),
Hide, Quit; closing the window quits; other ⌘ chords are not read as
plain letters; help shows ⌘.
- Follow the system light/dark appearance when no Omarchy theme exists.
- Worth a look knows Xcode DerivedData, DeviceSupport and ~/Library/Logs.
- git: skipped without the developer tools (its stub opens a dialog), and
never runs a checkout's programs: fsmonitor, hooks and pager off, and no
status for a checkout that defines its own filter drivers.
Packaging
- cargo xtask bundle builds disktree.app and a zip: Info.plist (bundle id
io.github.tobi.disktree, macOS 11+), an icon drawn from an SVG on the
macOS grid, ad-hoc or Developer ID signing, and --notarize.
- make install on macOS puts the app in ~/Applications and links
~/.local/bin/disktree to it.
- CI lints, tests and bundles on macOS; the release adds an arm64 macOS
zip, signed and notarized when the repository has the Apple secrets.
- scan: spawn_with takes a Known subtree and reuses it where the walk
reaches it, so widening from ~ to / reads only what is outside ~.
- filter: which nodes match a name, ignoring ASCII case without
allocating. Matches are kept whole; their ancestors are kept sized by
what matched beneath them.
- treemap: layout_filtered lays out only what a filter keeps.
- classify: a category per node (code, agent scratch, toolchains, synced,
git, media, documents, cache) from names and shapes — a bare repository
is git whatever it is called — and a reclaim reason for caches, sync
history, package stores and build output beside its manifest.
- insights: "worth a look", the largest findings that never nest:
reclaimable space, agent worktrees, experiments untouched for a month.
- nodes carry their newest write time, rolled up by aggregate.
- space: a mount-table model of a volume. One volume is one mount source,
so btrfs subvolumes (/home, /var/log) stay in and /proc, tmpfs, /boot,
network shares and automount points stay out, checked by path so a NAS
is never mounted to be measured. Staying on the volume is now the
default; volume_root finds the disk a home directory lives on.
- removal: system trees (/usr, /etc, /var/lib, /nix/store, …) are refused.
- treemap: wider gaps between top-level directories, full name bands only
at the first level and a slim label row below it.
- scan: dust's approach — one rayon scope, a +1 completion counter per
directory, bottom-up aggregation — with live progress and cancellation.
Disk usage by default, hardlinks counted once, symlinks not followed.
- tree: nodes with derived totals; aggregate() is the single source.
- treemap: squarified layout in viewport pixels, a name band per
subdivided directory, and crumbs that always address the scanned tree.
- space: statvfs, and the projection after removing marked bytes.
- removal: guarded plans (root, home, scanned root, mount points and
paths outside the root are refused), rm -rf semantics without a shell,
and trash via trash-put, gio or a built-in XDG implementation.