Skip to main content

resolve

Function resolve 

Source
pub fn resolve(path: &str) -> Cow<'_, str>
Expand description

Resolve a path argument for classification against the ambient cwd/root. Returns a path the existing classifiers (classify_locus, is_safe_write_target) can score unchanged. When cwd and root are both known and absolute, a relative path is lexically joined onto cwd (no filesystem access) and an absolute path is normalized in place; then either way, if the result is inside root it comes back as a root-relative path (so the classifiers see “worktree”), and if it escaped root (e.g. cwd is /etc, or an absolute /etc/hosts) it comes back absolute (so they see machine/etc.). This makes the absolute and relative spellings of the SAME in-root file classify identically — safety on the OPERATION, not the SYNTAX. A ~ (home) or $-unpinnable path, or no context, is returned as-is.