fn get_abs_path()

in src/path_rewriting.rs [131:160]


fn get_abs_path(source_dir: Option<&Path>, rel_path: PathBuf) -> Option<(PathBuf, PathBuf)> {
    let mut abs_path = if !rel_path.is_relative() {
        rel_path.to_owned()
    } else if let Some(source_dir) = source_dir {
        if !cfg!(windows) {
            guess_abs_path(source_dir, &rel_path)
        } else {
            guess_abs_path(
                source_dir,
                &PathBuf::from(&rel_path.to_str().unwrap().replace('/', "\\")),
            )
        }
    } else {
        rel_path.to_owned()
    };

    // Canonicalize, if possible.
    if let Ok(p) = canonicalize_path(&abs_path) {
        abs_path = p;
    }

    // Fixup the relative path, in case the absolute path was a symlink.
    let rel_path = fixup_rel_path(source_dir, &abs_path, rel_path);

    // Normalize the path in removing './' or '//' or '..'
    let rel_path = normalize_path(rel_path);
    let abs_path = normalize_path(abs_path);

    abs_path.zip(rel_path)
}