Repository navigation
fix(windows): pass verbatim \\?\ paths through untouched - #407
Conversation
…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
There was a problem hiding this comment.
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.
|
Thanks! 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. |
Fixes #406.
Problem
On Windows,
dua "\\?\D:\some\dir"fails withError: ... (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'sabsolute_verbatim_path(crates/dua-lib/src/windows.rs): when a relative path like.is resolved against a verbatim cwd (\\?\D:\dir, reachable becauseSetCurrentDirectoryWaccepts verbatim paths), the resulting absolute already carries the\\?\prefix — but the UNC branch matched any\\-prefixed path, re-prefixing it to\\?\UNC\?\D:\dir.CreateFileWthen returnsERROR_BAD_NETPATH. (Verified with a P/Invoke probe: those exact bytes reachCreateFileW.)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 fixesdua/dua <subdir>run from a verbatim cwd, andread_dir_types/OwnedHandle::open/Entry::from_pathwhich all funnel here.\\.\→\\?\rewrite and\\server\share→\\?\UNC\...mappings are unchanged.gix::path::normalizeis not the culprit — it's purely lexical and preserves verbatim prefixes; the corruption was entirely dua-side.Verified on real Windows 11
\\?\D:\diros error 53, rc=1\\?\D:\\.\D:\dir, normal, relative,aggregate, multi-argNew unit test covers all 7 prefix forms; 26/26 dua-core tests pass on actual Windows (cross-built test binary);
cargo fmt --check+clippyclean.