Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions crates/turborepo-paths/src/absolute_system_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ use crate::{
AbsoluteSystemPathBuf, AnchoredSystemPath, AnchoredSystemPathBuf, PathError, RelativeUnixPath,
};

fn clean_utf8_path(path: Utf8PathBuf) -> Utf8PathBuf {
match Utf8PathBuf::from_path_buf(path.as_std_path().clean()) {
Ok(cleaned) => cleaned,
Err(_) => path,
}
}

/// Models how two paths relate to each other
#[derive(Debug, PartialEq, Eq)]
pub enum PathRelation {
Expand Down Expand Up @@ -237,14 +244,7 @@ impl AbsoluteSystemPath {
/// Intended for joining literals or obviously single-token strings
pub fn join_component(&self, segment: &str) -> AbsoluteSystemPathBuf {
debug_assert!(!segment.contains(std::path::MAIN_SEPARATOR));
AbsoluteSystemPathBuf(
self.0
.join(segment)
.as_std_path()
.clean()
.try_into()
.unwrap(),
)
AbsoluteSystemPathBuf(clean_utf8_path(self.0.join(segment)))
}

/// Intended for joining a path composed of literals
Expand All @@ -254,14 +254,9 @@ impl AbsoluteSystemPath {
.iter()
.any(|segment| segment.contains(std::path::MAIN_SEPARATOR))
);
AbsoluteSystemPathBuf(
self.0
.join(segments.join(std::path::MAIN_SEPARATOR_STR))
.as_std_path()
.clean()
.try_into()
.unwrap(),
)
AbsoluteSystemPathBuf(clean_utf8_path(
self.0.join(segments.join(std::path::MAIN_SEPARATOR_STR)),
))
}

pub fn as_str(&self) -> &str {
Expand Down
21 changes: 11 additions & 10 deletions crates/turborepo-paths/src/anchored_system_path.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use std::{fmt, path::Path};

use camino::{Utf8Component, Utf8Path};
use camino::{Utf8Component, Utf8Path, Utf8PathBuf};
use path_clean::PathClean;
use serde::Serialize;

use crate::{AnchoredSystemPathBuf, PathError, PathRelation, RelativeUnixPathBuf};

fn clean_utf8_path(path: Utf8PathBuf) -> Utf8PathBuf {
match Utf8PathBuf::from_path_buf(path.as_std_path().clean()) {
Ok(cleaned) => cleaned,
Err(_) => path,
}
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Hash)]
#[serde(transparent)]
pub struct AnchoredSystemPath(Utf8Path);
Expand Down Expand Up @@ -113,18 +120,12 @@ impl AnchoredSystemPath {
.iter()
.any(|segment| segment.contains(std::path::MAIN_SEPARATOR))
);
AnchoredSystemPathBuf(
self.0
.join(segments.join(std::path::MAIN_SEPARATOR_STR))
.as_std_path()
.clean()
.try_into()
.unwrap(),
)
let joined = self.0.join(segments.join(std::path::MAIN_SEPARATOR_STR));
AnchoredSystemPathBuf(clean_utf8_path(joined))
}

pub fn clean(&self) -> AnchoredSystemPathBuf {
AnchoredSystemPathBuf(self.0.as_std_path().clean().try_into().unwrap())
AnchoredSystemPathBuf(clean_utf8_path(self.0.to_owned()))
}

/// relation_to_path does a lexical comparison of path components to
Expand Down
1 change: 0 additions & 1 deletion crates/turborepo-paths/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![deny(clippy::all)]
#![allow(clippy::unwrap_used)]

//! Turborepo's path handling library.
//! Defines distinct path types for the different uses of paths in Turborepo's
Expand Down
Loading