Skip to content

Commit 64fcaf0

Browse files
remove
1 parent c626ee7 commit 64fcaf0

File tree

1 file changed

+2
-44
lines changed

1 file changed

+2
-44
lines changed

crates/djls-source/src/path.rs

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,10 @@
11
mod clean;
22

3-
use std::path::Component;
4-
53
use camino::Utf8Path;
64
use camino::Utf8PathBuf;
75

8-
pub trait Utf8PathClean {
9-
fn clean(&self) -> Utf8PathBuf;
10-
}
11-
12-
impl Utf8PathClean for Utf8Path {
13-
fn clean(&self) -> Utf8PathBuf {
14-
clean_utf8_path(self)
15-
}
16-
}
17-
18-
impl Utf8PathClean for Utf8PathBuf {
19-
fn clean(&self) -> Utf8PathBuf {
20-
clean_utf8_path(self)
21-
}
22-
}
23-
24-
pub fn clean_utf8_path(path: &Utf8Path) -> Utf8PathBuf {
25-
let mut out = Vec::new();
26-
27-
for comp in path.as_std_path().components() {
28-
match comp {
29-
Component::CurDir => (),
30-
Component::ParentDir => match out.last() {
31-
Some(Component::RootDir) => (),
32-
Some(Component::Normal(_)) => {
33-
out.pop();
34-
}
35-
None | Some(Component::CurDir | Component::ParentDir | Component::Prefix(_)) => {
36-
out.push(comp);
37-
}
38-
},
39-
comp => out.push(comp),
40-
}
41-
}
42-
43-
if out.is_empty() {
44-
Utf8PathBuf::from(".")
45-
} else {
46-
let cleaned: std::path::PathBuf = out.iter().collect();
47-
Utf8PathBuf::from_path_buf(cleaned).expect("Path should still be UTF-8")
48-
}
49-
}
6+
use clean::clean_utf8_path;
7+
pub use clean::Utf8PathClean;
508

519
/// Django's `safe_join` equivalent - join paths and ensure result is within base
5210
pub fn safe_join(base: &Utf8Path, name: &str) -> Result<Utf8PathBuf, SafeJoinError> {

0 commit comments

Comments
 (0)