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

Function stash_entry_path

atomic-repository/src/repository/stash.rs:103–132  ·  view source on GitHub ↗
(root: &std::path::Path, path: &str)

Source from the content-addressed store, hash-verified

101}
102
103fn stash_entry_path(root: &std::path::Path, path: &str) -> Result<std::path::PathBuf, String> {
104 use std::path::Component;
105 let relative = std::path::Path::new(path);
106 if path.is_empty()
107 || relative
108 .components()
109 .any(|component| !matches!(component, Component::Normal(_)))
110 || relative.starts_with(".atomic")
111 || relative.starts_with(".atomic-sandbox")
112 {
113 return Err(format!("invalid stashed file path: {path}"));
114 }
115 // The leaf may be a symlink; only parents must be real directories.
116 let mut destination = root.to_path_buf();
117 let mut components = relative.components().peekable();
118 while let Some(component) = components.next() {
119 destination.push(component);
120 if components.peek().is_some() {
121 match std::fs::symlink_metadata(&destination) {
122 Ok(metadata) if metadata.file_type().is_symlink() => {
123 return Err(format!("refusing stashed file through symlink: {path}"));
124 }
125 Ok(_) => {}
126 Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}
127 Err(error) => return Err(format!("cannot inspect stashed file {path}: {error}")),
128 }
129 }
130 }
131 Ok(destination)
132}
133
134// A captured addition has no recorded version to materialize. Before removing
135// it from the working copy, verify that the saved entry still matches it.

Callers 2

stash_pushMethod · 0.85
stash_applyMethod · 0.85

Calls 6

componentsMethod · 0.80
is_emptyMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45
peekMethod · 0.45
kindMethod · 0.45

Tested by

no test coverage detected