Skip to content

Commit f6a43ea

Browse files
committed
Slightly less wasteful relative path parent function
1 parent 13f2097 commit f6a43ea

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

crates/lune-std/src/require/path_utils.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,10 @@ pub(crate) fn relative_path_normalize(path: &Path) -> PathBuf {
4646
number of times, and represent parent folders without first canonicalizing paths.
4747
*/
4848
pub(crate) fn relative_path_parent(rel: &mut PathBuf) {
49-
// If our relative path becomes empty, we should keep traversing it,
50-
// but we need to do so by appending the special "parent dir" component,
51-
// which is normally represented by ".."
52-
if rel.components().count() == 1 && rel.components().next().unwrap() == Component::CurDir {
53-
rel.pop();
54-
rel.push(Component::ParentDir);
55-
} else if rel.components().all(|c| matches!(c, Component::ParentDir)) {
56-
rel.push(Component::ParentDir);
49+
if rel.as_os_str() == Component::CurDir.as_os_str() {
50+
*rel = PathBuf::from(Component::ParentDir.as_os_str());
51+
} else if rel.components().all(|c| c == Component::ParentDir) {
52+
rel.push(Component::ParentDir.as_os_str());
5753
} else {
5854
rel.pop();
5955
}

0 commit comments

Comments
 (0)