| 569 | } |
| 570 | |
| 571 | fn validate_raw_bijection(write: &redb::WriteTransaction) -> Result<(), RepositoryError> { |
| 572 | let tree = write |
| 573 | .open_table(TREE) |
| 574 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 575 | let reverse = write |
| 576 | .open_table(REV_TREE) |
| 577 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 578 | let mut forward_count = 0usize; |
| 579 | let mut seen_inodes = HashSet::new(); |
| 580 | for row in tree |
| 581 | .iter() |
| 582 | .map_err(|error| RepositoryError::Database(error.to_string()))? |
| 583 | { |
| 584 | let (path, inode) = row.map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 585 | forward_count += 1; |
| 586 | if !seen_inodes.insert(inode.value()) { |
| 587 | return Err(RepositoryError::InvalidOperation { |
| 588 | message: format!( |
| 589 | "PATH_CLAIMS migration projected inode {} more than once", |
| 590 | inode.value() |
| 591 | ), |
| 592 | }); |
| 593 | } |
| 594 | let reverse_path = reverse |
| 595 | .get(inode.value()) |
| 596 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 597 | if reverse_path.as_ref().map(|value| value.value()) != Some(path.value()) { |
| 598 | return Err(RepositoryError::InvalidOperation { |
| 599 | message: format!( |
| 600 | "PATH_CLAIMS migration produced a non-bijective TREE row for '{}'", |
| 601 | path.value() |
| 602 | ), |
| 603 | }); |
| 604 | } |
| 605 | } |
| 606 | let mut reverse_count = 0usize; |
| 607 | for row in reverse |
| 608 | .iter() |
| 609 | .map_err(|error| RepositoryError::Database(error.to_string()))? |
| 610 | { |
| 611 | let (inode, path) = row.map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 612 | reverse_count += 1; |
| 613 | let forward_inode = tree |
| 614 | .get(path.value()) |
| 615 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 616 | if forward_inode.as_ref().map(|value| value.value()) != Some(inode.value()) { |
| 617 | return Err(RepositoryError::InvalidOperation { |
| 618 | message: format!( |
| 619 | "PATH_CLAIMS migration produced a reverse-only row for inode {}", |
| 620 | inode.value() |
| 621 | ), |
| 622 | }); |
| 623 | } |
| 624 | } |
| 625 | if forward_count != reverse_count { |
| 626 | return Err(RepositoryError::InvalidOperation { |
| 627 | message: format!( |
| 628 | "PATH_CLAIMS migration produced {} TREE rows and {} REV_TREE rows", |