MCPcopy Create free account
hub / github.com/codeinred/untree / normalize_path

Function normalize_path

lib/functions.rs:98–121  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

96}
97
98fn normalize_path(path: &Path) -> PathBuf {
99 let mut result = PathBuf::new();
100 let mut go_back = 0;
101 for component in path.components() {
102 match component.as_os_str().to_str() {
103 Some(".") => {}
104 Some("..") => {
105 if !result.pop() {
106 go_back += 1;
107 }
108 }
109 _ => result.push(component),
110 }
111 }
112 if go_back > 0 {
113 let mut prefix = PathBuf::new();
114 for _ in 0..go_back {
115 prefix.push("..");
116 }
117 prefix.push(result);
118 result = prefix;
119 }
120 result
121}
122
123/// Create a tree based on a sequence of lines describing the tree structure
124/// inside the given directory

Callers 1

create_treeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected