(&self, txn: &T)
| 284 | } |
| 285 | |
| 286 | fn validate<T: TreeTxnT + PathClaimTxnT>(&self, txn: &T) -> Result<(), TreeProjectionError> { |
| 287 | txn.validate_tree_bijection() |
| 288 | .map_err(|error| TreeProjectionError::IncompleteMetadata(error.to_string()))?; |
| 289 | let mut desired_claims = HashMap::<String, Vec<Inode>>::new(); |
| 290 | for (inode, entry) in &self.entries { |
| 291 | if let Some(Some(path)) = &entry.path { |
| 292 | desired_claims.entry(path.clone()).or_default().push(*inode); |
| 293 | } |
| 294 | } |
| 295 | for (path, claims) in &mut desired_claims { |
| 296 | claims.sort_by_key(|inode| inode.get()); |
| 297 | claims.dedup(); |
| 298 | if claims.len() > 1 { |
| 299 | return Err(TreeProjectionError::Conflict(format!( |
| 300 | "path '{}' has {} projected owners; PATH_CLAIMS must surface the conflict before TREE projection", |
| 301 | path, |
| 302 | claims.len() |
| 303 | ))); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | let moving_inodes: HashSet<Inode> = self |
| 308 | .entries |
| 309 | .iter() |
| 310 | .filter_map(|(inode, entry)| entry.path.is_some().then_some(*inode)) |
| 311 | .collect(); |
| 312 | |
| 313 | for (inode, entry) in &self.entries { |
| 314 | let current_path = txn |
| 315 | .get_path(*inode) |
| 316 | .map_err(|error| TreeProjectionError::Database(error.to_string()))?; |
| 317 | if let Some(path) = ¤t_path { |
| 318 | let primary = Self::validated_primary(txn, path)?.ok_or_else(|| { |
| 319 | TreeProjectionError::IncompleteMetadata(format!( |
| 320 | "REV_TREE maps inode {} to '{}', but TREE has no occupant", |
| 321 | inode.get(), |
| 322 | path |
| 323 | )) |
| 324 | })?; |
| 325 | if primary != *inode { |
| 326 | return Err(TreeProjectionError::IncompleteMetadata(format!( |
| 327 | "REV_TREE maps inode {} to '{}', but TREE maps it to inode {}", |
| 328 | inode.get(), |
| 329 | path, |
| 330 | primary.get() |
| 331 | ))); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | if let Some(position) = entry.binding { |
| 336 | let forward = txn |
| 337 | .inode_position(*inode) |
| 338 | .map_err(|error| TreeProjectionError::Database(error.to_string()))?; |
| 339 | let reverse = txn |
| 340 | .position_inode(position) |
| 341 | .map_err(|error| TreeProjectionError::Database(error.to_string()))?; |
| 342 | match (forward, reverse) { |
| 343 | (None, None) => {} |
no test coverage detected