(path: &Path, plan: MigrationPlan)
| 404 | } |
| 405 | |
| 406 | fn commit_migration(path: &Path, plan: MigrationPlan) -> Result<(), RepositoryError> { |
| 407 | let db = redb::Builder::new() |
| 408 | .set_cache_size(8 * 1024 * 1024 * 1024) |
| 409 | .open(path) |
| 410 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 411 | let write = db |
| 412 | .begin_write() |
| 413 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 414 | |
| 415 | { |
| 416 | let mut inodes = write |
| 417 | .open_table(INODES) |
| 418 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 419 | let mut reverse = write |
| 420 | .open_table(REV_INODES) |
| 421 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 422 | for (inode, position) in &plan.recovered_inodes { |
| 423 | let encoded = encode_position(position.change.get(), position.pos.get()); |
| 424 | let existing_position = inodes |
| 425 | .get(inode.get()) |
| 426 | .map_err(|error| RepositoryError::Database(error.to_string()))? |
| 427 | .map(|value| *value.value()); |
| 428 | if existing_position.is_some_and(|existing| existing != encoded) { |
| 429 | return Err(RepositoryError::InvalidOperation { |
| 430 | message: format!( |
| 431 | "cannot restore inode {} at {}: INODES already has another position", |
| 432 | inode.get(), |
| 433 | position |
| 434 | ), |
| 435 | }); |
| 436 | } |
| 437 | let existing_inode = reverse |
| 438 | .get(&encoded) |
| 439 | .map_err(|error| RepositoryError::Database(error.to_string()))? |
| 440 | .map(|value| value.value()); |
| 441 | if existing_inode.is_some_and(|existing| existing != inode.get()) { |
| 442 | return Err(RepositoryError::InvalidOperation { |
| 443 | message: format!( |
| 444 | "cannot restore inode {} at {}: REV_INODES already has inode {}", |
| 445 | inode.get(), |
| 446 | position, |
| 447 | existing_inode.unwrap() |
| 448 | ), |
| 449 | }); |
| 450 | } |
| 451 | inodes |
| 452 | .insert(inode.get(), &encoded) |
| 453 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 454 | reverse |
| 455 | .insert(&encoded, inode.get()) |
| 456 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | let claim_paths = { |
| 461 | let table = write |
| 462 | .open_multimap_table(PATH_CLAIMS) |
| 463 | .map_err(|error| RepositoryError::Database(error.to_string()))?; |
no test coverage detected