#[cfg(test)]
mod tests;
use std::path::{Component, Path, PathBuf};
pub fn prefix_with_current_dir<P: AsRef<Path>>(path: P) -> PathBuf {
fn do_prefix_with_current_dir(path: &Path) -> PathBuf {
let components = path.components().collect::<Vec<Component>>();
if !components.is_empty() {
if let Component::Normal(_) = components[0] {
return <Component<'_> as AsRef<Path>>::as_ref(&Component::CurDir).join(path);
} else {
return path.to_path_buf();
}
}
<Component<'_> as AsRef<Path>>::as_ref(&Component::CurDir).to_path_buf()
}
do_prefix_with_current_dir(path.as_ref())
}