| 1 |
# Dunce (de-UNC) |
| 2 |
|
| 3 |
In Windows the regular paths (`C:\foo`) are supported by all programs, |
| 4 |
but have lots of bizarre restrictions for backwards compatibility with MS-DOS. |
| 5 |
There are also Windows NT UNC paths (`\\?\C:\foo`), which are more robust and with fewer gotchas, |
| 6 |
but are rarely supported by Windows programs — even Microsoft's own! |
| 7 |
|
| 8 |
This crate converts Windows UNC paths to the MS-DOS-compatible format whenever possible, |
| 9 |
but leaves UNC paths as-is when they can't be unambiguously expressed in a simpler way. |
| 10 |
This allows legacy programs to access all paths they can possibly access, |
| 11 |
and doesn't break any paths for UNC-aware programs. |
| 12 |
|
| 13 |
For example, `\\?\C:\Windows` will be converted to `C:\Windows`, but `\\?\C:\COM` will be |
| 14 |
left as-is, because it contains a reserved filename. |
| 15 |
|
| 16 |
In Rust the worst UNC offender is the `fs::canonicalize()` function. This crate provides |
| 17 |
a drop-in replacement for it that returns paths you'd expect. |
| 18 |
|
| 19 |
On non-Windows platforms these functions leave paths unmodified, so it's safe to use them |
| 20 |
unconditionally for all platforms. |
| 21 |
|
| 22 |
This crate's handling of UNC paths is safer than just unconditionally stripping the `\\` prefix, |
| 23 |
because naively stripped UNC paths with hostnames change to relative directory paths. There are |
| 24 |
other normalization rules, special characters, and length limits that could change meaning |
| 25 |
of the path. |
| 26 |
|
| 27 |
Parsing is based on <https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx>. |