(path: &str, allow_vcs_names: bool)
| 4816 | } |
| 4817 | |
| 4818 | fn 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 | |
| 4861 | fn resolve_without_symlink_parents( |
| 4862 | base: &Path, |
no test coverage detected