(
&self,
request: Request<UnrecordRequest>,
)
| 2666 | } |
| 2667 | |
| 2668 | async fn unrecord( |
| 2669 | &self, |
| 2670 | request: Request<UnrecordRequest>, |
| 2671 | ) -> Result<Response<UnrecordResponse>, Status> { |
| 2672 | let request = request.into_inner(); |
| 2673 | let handle = self |
| 2674 | .state |
| 2675 | .resolve(request.repository.as_ref().unwrap_or(&default_ref()))?; |
| 2676 | self.state.log_rpc("Unrecord", Some(&handle)); |
| 2677 | let gate_handle = handle.clone(); |
| 2678 | let _gate = gate_handle.exclusive().await; |
| 2679 | let result = tokio::task::spawn_blocking(move || -> Result<UnrecordResponse, Status> { |
| 2680 | let (repo, _workspace) = |
| 2681 | handle.workspace_repository(atomic_repository::WorkspaceTxnMode::Reconcile)?; |
| 2682 | let options = atomic_repository::UnrecordOptions::new(); |
| 2683 | let outcome = match request |
| 2684 | .target |
| 2685 | .as_ref() |
| 2686 | .and_then(|target| target.kind.clone()) |
| 2687 | { |
| 2688 | Some(change_ref::Kind::Hash(hash)) => { |
| 2689 | let mut bytes = [0u8; 32]; |
| 2690 | if hash.value.len() != 32 { |
| 2691 | return Err(domain_status( |
| 2692 | ErrorCode::InvalidArgument, |
| 2693 | "hash must be 32 bytes", |
| 2694 | )); |
| 2695 | } |
| 2696 | bytes.copy_from_slice(&hash.value); |
| 2697 | repo.unrecord(&atomic_core::types::Merkle(bytes), options) |
| 2698 | .map_err(repository_error)? |
| 2699 | } |
| 2700 | Some(change_ref::Kind::Sequence(_)) => { |
| 2701 | return Err(domain_status( |
| 2702 | ErrorCode::InvalidArgument, |
| 2703 | "unrecord takes a hash target (or none for the last change)", |
| 2704 | )) |
| 2705 | } |
| 2706 | // Case-insensitive unique-prefix resolution over the whole |
| 2707 | // change store; the unrecord membership guard speaks. |
| 2708 | Some(change_ref::Kind::Prefix(prefix)) => { |
| 2709 | let prefix = prefix.trim().to_ascii_uppercase(); |
| 2710 | match repo.find_change_by_prefix(&prefix) { |
| 2711 | Ok(Some(hash)) => { |
| 2712 | repo.unrecord(&hash, options).map_err(repository_error)? |
| 2713 | } |
| 2714 | Ok(None) => { |
| 2715 | return Err(domain_status( |
| 2716 | ErrorCode::NotFound, |
| 2717 | format!("no change found matching '{prefix}'"), |
| 2718 | )) |
| 2719 | } |
| 2720 | Err(atomic_repository::RepositoryError::AmbiguousHash { |
| 2721 | prefix, |
| 2722 | matches, |
| 2723 | }) => { |
| 2724 | return Err(domain_status( |
| 2725 | ErrorCode::NotFound, |
no test coverage detected