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

Function deletion_path

atomic-repository/src/repository/stash.rs:156–181  ·  view source on GitHub ↗

A deletion is a working-copy operation, not a new claim about graph paths. Refuse malformed paths and symlink traversal before deleting anything.

(root: &std::path::Path, path: &str)

Source from the content-addressed store, hash-verified

154// A deletion is a working-copy operation, not a new claim about graph paths.
155// Refuse malformed paths and symlink traversal before deleting anything.
156fn deletion_path(root: &std::path::Path, path: &str) -> Result<std::path::PathBuf, String> {
157 use std::path::Component;
158 let relative = std::path::Path::new(path);
159 if path.is_empty()
160 || relative
161 .components()
162 .any(|c| !matches!(c, Component::Normal(_)))
163 || relative.starts_with(".atomic")
164 || relative.starts_with(".atomic-sandbox")
165 {
166 return Err(format!("invalid stashed deletion path: {path}"));
167 }
168 let mut destination = root.to_path_buf();
169 for component in relative.components() {
170 destination.push(component);
171 match std::fs::symlink_metadata(&destination) {
172 Ok(meta) if meta.file_type().is_symlink() => {
173 return Err(format!("refusing stashed deletion through symlink: {path}"));
174 }
175 Ok(_) => {}
176 Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
177 Err(e) => return Err(format!("cannot inspect stashed deletion {path}: {e}")),
178 }
179 }
180 Ok(destination)
181}
182
183/// One stash: an orphan view plus its parsed metadata.
184#[derive(Debug, Clone)]

Callers 1

stash_applyMethod · 0.85

Calls 4

componentsMethod · 0.80
is_emptyMethod · 0.45
pushMethod · 0.45
kindMethod · 0.45

Tested by

no test coverage detected