Skip to content

fix(windows): pass verbatim \\?\ paths through untouched - #407

Merged
Byron merged 1 commit into
Byron:mainfrom
Mathjk:fix/verbatim-path
Sep 29, 2026
Merged

Byron merged 1 commit into
Byron:mainfrom
Mathjk:fix/verbatim-path

Conversation

@Mathjk

@Mathjk Mathjk commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #406.

Problem

On Windows, dua "\\?\D:\some\dir" fails with Error: ... (os error 53) (ERROR_BAD_NETPATH). Verbatim paths are the canonical way to express long paths on Windows, and every other tool tested (dust, tokei, hexyl) accepts the same input.

Root cause

dua-lib's absolute_verbatim_path (crates/dua-lib/src/windows.rs): when a relative path like . is resolved against a verbatim cwd (\\?\D:\dir, reachable because SetCurrentDirectoryW accepts verbatim paths), the resulting absolute already carries the \\?\ prefix — but the UNC branch matched any \\-prefixed path, re-prefixing it to \\?\UNC\?\D:\dir. CreateFileW then returns ERROR_BAD_NETPATH. (Verified with a P/Invoke probe: those exact bytes reach CreateFileW.)

Fix

Extract the absolute→verbatim encoding into verbatim_path_units() and add an early pass-through for paths already carrying \\?\ or \??\ — verbatim means "do not modify" per Win32 semantics. This also fixes dua/dua <subdir> run from a verbatim cwd, and read_dir_types/OwnedHandle::open/Entry::from_path which all funnel here. \\.\→\\?\ rewrite and \\server\share→\\?\UNC\... mappings are unchanged.

gix::path::normalize is not the culprit — it's purely lexical and preserves verbatim prefixes; the corruption was entirely dua-side.

Verified on real Windows 11

input before after
\\?\D:\dir os error 53, rc=1 enumerates, rc=0
\\?\D: error 53 full scan works
\\.\D:\dir, normal, relative, aggregate, multi-arg — all unchanged

New unit test covers all 7 prefix forms; 26/26 dua-core tests pass on actual Windows (cross-built test binary); cargo fmt --check + clippy clean.

…ndows

When the current directory is verbatim (e.g. after `dua "\\?\D:\dir"`
chdirs into a verbatim input path, or when dua runs from a verbatim cwd),
`absolute_verbatim_path` resolved relative paths like "." into an
already-verbatim absolute path, then fed it into the generic `\\` (UNC)
branch and produced `\\?\UNC\?\D:\dir`. `CreateFileW` on that path fails
with `ERROR_BAD_NETPATH` (os error 53), so `dua`/`dua aggregate` could not
enumerate `\\?\` directories at all.

An absolute path that already carries a `\\?\` or `\??\` prefix is now
passed through untouched, matching Win32 verbatim semantics; `\\.\`,
UNC and ordinary local paths are unchanged.

Fixes Byron#406

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused fix addresses the reported path corruption without altering existing conversion behavior.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes Windows verbatim-path handling by preserving existing \\?\ and \??\ prefixes.

Changes:

  • Extracts verbatim path encoding into a helper.
  • Adds regression coverage for seven Windows path forms.
File Description
crates/​dua-lib/​src/​windows.rs Preserves verbatim paths and tests prefix conversion behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Byron

Byron commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Thanks!
I did an armchair review, and nothing stuck out. Also, Codex running on Windows didn't find anything, and I am sure it poked the code quite a bit.
So let's bring it in.


No actionable regressions were found. Windows core tests and isolated localization/path checks passed; the full workspace suite could not run offline because some dependencies were not cached.

@Byron
Byron merged commit 8f8d25b into Byron:main Sep 29, 2026
3 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.

Windows: \\?\ verbatim directory paths fail with ERROR_BAD_NETPATH (os error 53)

3 participants