| 210 | } |
| 211 | |
| 212 | fn validate_repo_path(bytes: &[u8]) -> Result<(), ProjectTreeError> { |
| 213 | if bytes.is_empty() { |
| 214 | return Err(ProjectTreeError::InvalidPath("path is empty".into())); |
| 215 | } |
| 216 | if bytes[0] == b'/' { |
| 217 | return Err(ProjectTreeError::InvalidPath("path is absolute".into())); |
| 218 | } |
| 219 | if bytes.contains(&0) { |
| 220 | return Err(ProjectTreeError::InvalidPath("path contains NUL".into())); |
| 221 | } |
| 222 | for component in bytes.split(|byte| *byte == b'/') { |
| 223 | if component.is_empty() { |
| 224 | return Err(ProjectTreeError::InvalidPath( |
| 225 | "path contains an empty component".into(), |
| 226 | )); |
| 227 | } |
| 228 | if component == b"." || component == b".." { |
| 229 | return Err(ProjectTreeError::InvalidPath( |
| 230 | "path contains '.' or '..'".into(), |
| 231 | )); |
| 232 | } |
| 233 | } |
| 234 | Ok(()) |
| 235 | } |
| 236 | |
| 237 | #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 238 | pub enum ExclusionReason { |