MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / resolve_dot_segments

Function resolve_dot_segments

crates/openshell-supervisor-network/src/l7/path.rs:237–265  ·  view source on GitHub ↗
(segments: Vec<&[u8]>)

Source from the content-addressed store, hash-verified

235}
236
237fn resolve_dot_segments(segments: Vec<&[u8]>) -> Result<Vec<Vec<u8>>, CanonicalizeError> {
238 let mut stack: Vec<Vec<u8>> = Vec::with_capacity(segments.len());
239 let last = segments.len().saturating_sub(1);
240 for (idx, seg) in segments.into_iter().enumerate() {
241 if seg == b".." {
242 if stack.pop().is_none() {
243 return Err(CanonicalizeError::TraversalAboveRoot);
244 }
245 if idx == last {
246 // A trailing `..` leaves a "directory" (trailing slash).
247 stack.push(Vec::new());
248 }
249 continue;
250 }
251 if seg == b"." {
252 if idx == last {
253 stack.push(Vec::new());
254 }
255 continue;
256 }
257 if seg.is_empty() && idx != last {
258 // Collapse repeated slashes except at the very end, where an
259 // empty trailing segment encodes a trailing `/`.
260 continue;
261 }
262 stack.push(seg.to_vec());
263 }
264 Ok(stack)
265}
266
267fn build_canonical_path(
268 segments: &[Vec<u8>],

Callers 1

Calls 3

lenMethod · 0.80
pushMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected