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

Function validate_relative_path

atomic-repository/src/repository/operation.rs:4818–4859  ·  view source on GitHub ↗
(path: &str, allow_vcs_names: bool)

Source from the content-addressed store, hash-verified

4816}
4817
4818fn validate_relative_path(path: &str, allow_vcs_names: bool) -> Result<PathBuf, RepositoryError> {
4819 if path.is_empty() {
4820 return Err(RepositoryError::InvalidOperation {
4821 message: "operation effect path cannot be empty".to_string(),
4822 });
4823 }
4824 let candidate = Path::new(path);
4825 let mut clean = PathBuf::new();
4826 for component in candidate.components() {
4827 match component {
4828 Component::Normal(value) => clean.push(value),
4829 Component::Prefix(_)
4830 | Component::RootDir
4831 | Component::CurDir
4832 | Component::ParentDir => {
4833 return Err(RepositoryError::InvalidOperation {
4834 message: format!("unsafe operation effect path '{path}'"),
4835 })
4836 }
4837 }
4838 }
4839 if clean.as_os_str().is_empty() {
4840 return Err(RepositoryError::InvalidOperation {
4841 message: format!("unsafe operation effect path '{path}'"),
4842 });
4843 }
4844 if !allow_vcs_names {
4845 let first = clean
4846 .components()
4847 .next()
4848 .and_then(|component| match component {
4849 Component::Normal(value) => Some(value),
4850 _ => None,
4851 });
4852 if first == Some(OsStr::new(".atomic")) || first == Some(OsStr::new(".git")) {
4853 return Err(RepositoryError::InvalidOperation {
4854 message: format!("operation filesystem effect cannot target '{path}'"),
4855 });
4856 }
4857 }
4858 Ok(clean)
4859}
4860
4861fn resolve_without_symlink_parents(
4862 base: &Path,

Callers 1

Calls 4

componentsMethod · 0.80
is_emptyMethod · 0.45
pushMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected