MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / normalize_path

Function normalize_path

atomic-core/src/output/filesystem/paths.rs:40–59  ·  view source on GitHub ↗

Normalize a path by resolving `.` and `..` components. Unlike `canonicalize()`, this doesn't require the path to exist.

(path: &Path)

Source from the content-addressed store, hash-verified

38///
39/// Unlike `canonicalize()`, this doesn't require the path to exist.
40pub(crate) fn normalize_path(path: &Path) -> PathBuf {
41 use std::path::Component;
42
43 let mut normalized = PathBuf::new();
44
45 for component in path.components() {
46 match component {
47 Component::Prefix(p) => normalized.push(p.as_os_str()),
48 Component::RootDir => normalized.push(component.as_os_str()),
49 Component::CurDir => {} // Skip `.`
50 Component::ParentDir => {
51 // Go up one level, but don't go above root
52 normalized.pop();
53 }
54 Component::Normal(name) => normalized.push(name),
55 }
56 }
57
58 normalized
59}
60
61// PERMISSION HELPERS
62

Callers 5

resolve_pathMethod · 0.70

Calls 1

pushMethod · 0.45

Tested by 4