Skip to content

Never delete into a filesystem mounted inside a marked directory - #10

Merged
tobi merged 2 commits into
tobi:mainfrom
mdsilvers:fix/removal-nested-mounts
Sep 25, 2026
Merged

tobi merged 2 commits into
tobi:mainfrom
mdsilvers:fix/removal-nested-mounts

Conversation

@mdsilvers

Copy link
Copy Markdown
Contributor

Fixes #9.

Mounts inside a target (removal.rs)

fs::remove_dir_all crosses mount boundaries. Permanently deleting a marked directory therefore emptied anything mounted below it, and only then failed with EBUSY on the mount point. A one-filesystem scan never shows that content.

  • Plan: a target with any /proc/self/mounts entry strictly beneath it is blocked, and the review screen shows the reason.
  • Removal: remove_permanently walks the tree itself. Each directory is opened relative to its parent with openat(O_DIRECTORY|O_NOFOLLOW) through rustix, which is already a dependency. The walk stops with an error at a child directory whose st_dev or statx mount ID differs from the target's.
    • The mount ID matters: a bind mount of the same filesystem keeps its st_dev, and a device check alone still deleted through it in testing.
    • Symlinks are unlinked, never followed, as before.
    • An unmounted nested btrfs subvolume also has its own st_dev, so the walk won't descend into it. That matches rm --one-file-system and the existing is_mount_point rule.

git status in untrusted checkouts (git.rs)

A repository's .git/config can set core.fsmonitor to a program, and git runs it on every status. safe.directory doesn't apply to repos the user owns. The git calls now pass -c core.fsmonitor=false -c core.hooksPath=/dev/null -c core.pager=cat; command-line config outranks the repository's own config.

Verification

  • cargo xtask lint and cargo xtask test pass. New tests cover:
    • the mount-below refusal
    • nested trees, hidden files and nested symlinks under the new walker
    • a planted fsmonitor script that must not run
  • In a user namespace (unshare -rm), with a same-filesystem bind mount and a tmpfs mounted under a marked directory:
    • before: the mounted files were deleted
    • after: plan blocks the target, and remove_permanently called directly stops at the mount with nothing on it touched
    • an ordinary tree containing a symlink to /etc is still removed completely

🤖 Generated with Claude Code

mdsilvers and others added 2 commits September 25, 2026 13:57
remove_dir_all crosses mount boundaries, so permanently deleting a marked
directory emptied anything mounted below it (sshfs, NFS, a USB disk, a
bind mount) before failing with EBUSY on the mount point. A one-filesystem
scan never shows that content, so it was data the user never saw.

The plan now refuses a target with a mount point beneath it, and the
removal walks the tree itself with openat(O_NOFOLLOW), stopping at a
directory on another device or mount (statx mount ID, which also sees
same-filesystem bind mounts).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A repository's .git/config can set core.fsmonitor to a program, which git
runs on every status; safe.directory does not cover repos the user owns.
Selecting a directory now overrides fsmonitor, hooksPath and pager on the
command line, which outranks repository config.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@tobi
tobi merged commit 83c7bcc into tobi:main Sep 25, 2026
pull Bot pushed a commit to jasonkneen/disktree that referenced this pull request Sep 25, 2026
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 tobi#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permanent deletion empties filesystems mounted inside a marked directory

2 participants