fud_core/utils.rs
1use camino::{Utf8Path, Utf8PathBuf};
2use pathdiff::diff_utf8_paths;
3
4/// Get a version of `path` that works when the working directory is `base`. This is
5/// opportunistically a relative path, but we can always fall back to an absolute path to make sure
6/// the path still works.
7pub fn relative_path(path: &Utf8Path, base: &Utf8Path) -> Utf8PathBuf {
8 match diff_utf8_paths(path, base) {
9 Some(p) => p,
10 None => path
11 .canonicalize_utf8()
12 .expect("could not get absolute path"),
13 }
14}