#unc #canonicalize #realpath #windows #deunc

dunce

Normalize Windows paths to the most compatible format, avoiding UNC where possible

5 releases (stable)

1.0.4 Apr 19, 2023
1.0.3 Oct 6, 2022
1.0.2 Jun 8, 2021
1.0.1 Jun 2, 2020
0.1.0 Nov 22, 2017

#15 in Filesystem

Download history 222223/week @ 2023-11-25 209774/week @ 2023-12-02 218093/week @ 2023-12-09 204484/week @ 2023-12-16 142418/week @ 2023-12-23 185551/week @ 2023-12-30 228822/week @ 2024-01-06 259038/week @ 2024-01-13 265038/week @ 2024-01-20 278483/week @ 2024-01-27 269385/week @ 2024-02-03 275225/week @ 2024-02-10 275153/week @ 2024-02-17 290360/week @ 2024-02-24 293166/week @ 2024-03-02 127663/week @ 2024-03-09

1,029,856 downloads per month
Used in 1,675 crates (217 directly)

CC0-1.0 OR MIT-0 OR Apache-2.0

15KB
275 lines

Dunce (de-UNC)

In Windows the regular paths (C:\foo) are supported by all programs, but have lots of bizarre restrictions for backwards compatibility with MS-DOS. There are also Windows NT UNC paths (\\?\C:\foo), which are more robust and with fewer gotchas, but are rarely supported by Windows programs. Even Microsoft's own!

This crate converts Windows UNC paths to the MS-DOS-compatible format whenever possible, but leaves UNC paths as-is when they can't be unambiguously expressed in a simpler way. This allows legacy programs to access all paths they can possibly access, and doesn't break any paths for UNC-aware programs.

In Rust the worst UNC offender is the fs::canonicalize() function. This crate provides a drop-in replacement for it that returns paths you'd expect.

On non-Windows platforms these functions leave paths unmodified, so it's safe to use them unconditionally for all platforms.


lib.rs:

Filesystem paths in Windows are a total mess. This crate normalizes paths to the most compatible (but still correct) format, so that you don't have to worry about the mess.

In Windows the regular/legacy paths (C:\foo) are supported by all programs, but have lots of bizarre restrictions for backwards compatibility with MS-DOS.

And there are Windows NT UNC paths (\\?\C:\foo), which are more robust and with fewer gotchas, but are rarely supported by Windows programs. Even Microsoft's own!

This crate converts paths to legacy format whenever possible, but leaves UNC paths as-is when they can't be unambiguously expressed in a simpler way. This allows legacy programs to access all paths they can possibly access, and UNC-aware programs to access all paths.

On non-Windows platforms these functions leave paths unmodified, so it's safe to use them unconditionally for all platforms.

Parsing is based on https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

Project homepage.

No runtime deps