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>)
| 62 | /// no empty components, no reserved bookkeeping names), normalized to |
| 63 | /// `component/component` form. Empty or unset means the whole view. |
| 64 | fn 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 | |
| 93 | fn invalid(message: impl Into<String>) -> Status { |
| 94 | domain_status(ErrorCode::InvalidArgument, message) |
no test coverage detected