Skip to main content

canonicalize

Function canonicalize 

Source
pub fn canonicalize(path: &Path) -> Result<PathBuf>
Expand description

Canonicalize path, stripping the Windows \\?\ verbatim prefix whenever the simplified form is unambiguous. On Unix this is a plain canonicalize.

std::fs::canonicalize (and fs_err’s wrapper) return extended-length \\?\C:\… paths on Windows. Those break every consumer that matters here: cd '\\?\C:\…' fails in cmd.exe, the prefix surfaces verbatim in list / status / doctor output, and the leading \\?\ is not what a user ever typed. dunce::simplified drops the prefix when the path stays valid without it (the common case for repo paths) and preserves it untouched when it is genuinely required — paths beyond MAX_PATH, or components illegal in a normal Win32 path.

§Errors

Propagates the std::io::Error from the underlying canonicalize — most commonly std::io::ErrorKind::NotFound when path does not exist — carrying fs_err’s path context in the message.