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

Function materialize_prefix

libatomic/src/daemon/services_sandbox.rs:64–91  ·  view source on GitHub ↗

Validate a Materialize path prefix: plain relative components only (the same lexical rules as the entries it filters — no `..`, no `.`, no root, no empty components, no reserved bookkeeping names), normalized to `component/component` form. Empty or unset means the whole view.

(path_prefix: Option<String>)

Source from the content-addressed store, hash-verified

62/// no empty components, no reserved bookkeeping names), normalized to
63/// `component/component` form. Empty or unset means the whole view.
64fn materialize_prefix(path_prefix: Option<String>) -> Result<Option<String>, Status> {
65 use std::path::{Component, Path};
66 let Some(prefix) = path_prefix else {
67 return Ok(None);
68 };
69 if prefix.is_empty() {
70 return Ok(None);
71 }
72 let refuse = |why: &str| invalid(format!("refusing materialize prefix {prefix:?}: {why}"));
73 let relative = Path::new(&prefix);
74 if !relative.is_relative() {
75 return Err(refuse("not a relative path"));
76 }
77 let mut parts = Vec::new();
78 for part in relative.components() {
79 let Component::Normal(name) = part else {
80 return Err(refuse("not a plain relative path"));
81 };
82 if name == ".atomic" || name == ".atomic-sandbox" || name == ".atomic-sandbox.d" {
83 return Err(refuse("names the sandbox's own bookkeeping"));
84 }
85 parts.push(name.to_string_lossy().into_owned());
86 }
87 if parts.is_empty() {
88 return Err(refuse("empty path"));
89 }
90 Ok(Some(parts.join("/")))
91}
92
93fn invalid(message: impl Into<String>) -> Status {
94 domain_status(ErrorCode::InvalidArgument, message)

Callers 1

materializeMethod · 0.70

Calls 5

refuseFunction · 0.85
componentsMethod · 0.80
invalidFunction · 0.70
is_emptyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected