Skip to main content

absolute

Function absolute 

Source
pub fn absolute(path: &str) -> String
Expand description

convert a (possibly relative) file path to an absolute one

std::fs::canonicalize requires the path to exist; many callers hand us paths that haven’t been resolved yet (e.g. \import{subdir}{f.sty} constructs subdir/f.sty before find_file probes other dirs). Mirror Perl’s Cwd::abs_path-style behavior: produce a lexically absolute path joined against current_dir() when the input is relative, then run it through our canonical() to collapse ./.. components.

Panics only if current_dir() itself fails — that means the cwd was deleted out from under us, which we cannot safely resolve a relative path against (and silently returning the input could let a relative file reference target an attacker-controlled path).