Skip to content

Fix -x / --limit-filesystem on Windows - #653

Merged
bootandy merged 1 commit into
bootandy:masterfrom
armadavalor:fix-windows-limit-filesystem
Nov 19, 2026
Merged

bootandy merged 1 commit into
bootandy:masterfrom
armadavalor:fix-windows-limit-filesystem

Conversation

@armadavalor

Copy link
Copy Markdown

On Windows -x / --limit-filesystem does nothing.

get_filesystem_devices takes the device from get_metadata, but the cheap Windows path returns None for the inode/device of plain files and directories. So allowed_filesystems ends up empty and the check in ignore_file never runs. Entries inside the walk have no device either, so the check could not fire even with a non-empty set.

You notice this with -L. A junction on C: that points into T: is still followed with -L -x:

mkdir t1\a
mklink /J t1\cj T:\some\dir
dust -L -x t1      # cj and its contents are still listed

Fix:

  • Add platform::get_volume_serial on Windows. It opens a handle with only FILE_READ_ATTRIBUTES (plus FILE_FLAG_BACKUP_SEMANTICS so directories open) and reads the volume serial.
  • On Windows, get_filesystem_devices uses it for the target dirs.
  • In ignore_file it is used only for followed links (symlink, junction, mounted folder), since those are the only entries that can lead to another volume. Plain files and dirs keep the cheap path, so there is no extra cost unless -L -x is used.

Tested on Windows 10:

  • cargo test: all pass.
  • cargo clippy -- -D warnings is clean for the crate. --all-targets reports empty_line_after_doc_comments in tests/test_flags.rs and tests/test_exact_output.rs, which is already on master.
  • By hand, with a dir on C: holding one junction into T: and one junction into the same dir: -L -x now drops the T: junction and keeps the same-volume one. -L alone lists both, as before. -x on a plain dir gives the same output as before.

Not tested: symlinks (creating them needs admin here), mounted-folder volumes, and Linux/macOS. The non-Windows code path is unchanged apart from a moved use.

The cheap Windows metadata path never returns a volume serial, so the
allowed filesystem set was always empty and -x did nothing. With -L,
dust followed junctions and symlinks onto other volumes.

Read the volume serial with a handle for the target dirs and for
followed links, the only entries that can lead to another volume.
@bootandy

Copy link
Copy Markdown
Owner

thanks, I dont have a windows system, so i cant check. But it seems to make sense

@bootandy
bootandy merged commit ccc07c7 into bootandy:master Nov 19, 2026
19 checks passed
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.

2 participants