Skip to main content

Module pathfmt

Module pathfmt 

Source
Expand description

Rendering filesystem paths for the two audiences Trail has: the operating system, and the person reading the screen.

std::fs::canonicalize returns every absolute Windows path in extended-length (verbatim) form — \\?\C:\Users\me, not C:\Users\me. That form is what Win32 wants when a path may be longer than MAX_PATH, and it is not what anyone types, reads, or pastes back into a shell. Trail canonicalizes its current directory at startup, so without this module the prefix leaks into the nav panel title, the status bar, ya (yank absolute path), the --cwd-file handoff and the trail --paths report.

§The two operations are not the same

display renders a path for a human and always drops the prefix. The result is text that is never handed back to the filesystem, so dropping it cannot break anything.

simplified rewrites a path Trail keeps using, so it drops the prefix only when the plain spelling addresses the very same file. A path past MAX_PATH, and a name only the verbatim form can express — a reserved DOS device name, a component ending in a dot or a space, a component holding a character Win32 reads as a separator or a wildcard — keeps the prefix and stays correct.

On every non-Windows platform simplified is the identity: a backslash is an ordinary character in a Unix file name, so a file really can be named \\?\C:\x and rewriting it would point somewhere else.

Functions§

canonicalize
std::fs::canonicalize with the Windows verbatim prefix dropped where simplified finds it safe to drop.
display
Renders path the way a person would type it.
elide_front
Returns path with the Windows verbatim prefix dropped when the plain spelling addresses the same file, and unchanged otherwise.
simplified