(
&self,
request: Request<UnrecordRequest>,
)
| 2701 | } |
| 2702 | |
| 2703 | async fn unrecord( |
| 2704 | &self, |
| 2705 | request: Request<UnrecordRequest>, |
| 2706 | ) -> Result<Response<UnrecordResponse>, Status> { |
| 2707 | let request = request.into_inner(); |
| 2708 | let handle = self |
| 2709 | .state |
| 2710 | .resolve(request.repository.as_ref().unwrap_or(&default_ref()))?; |
| 2711 | self.state.log_rpc("Unrecord", Some(&handle)); |
| 2712 | let gate_handle = handle.clone(); |
| 2713 | let _gate = gate_handle.exclusive().await; |
| 2714 | let result = tokio::task::spawn_blocking(move || -> Result<UnrecordResponse, Status> { |
| 2715 | let (repo, _workspace) = |
| 2716 | handle.workspace_repository(atomic_repository::WorkspaceTxnMode::Reconcile)?; |
| 2717 | let options = atomic_repository::UnrecordOptions::new(); |
| 2718 | let outcome = match request |
| 2719 | .target |
| 2720 | .as_ref() |
| 2721 | .and_then(|target| target.kind.clone()) |
| 2722 | { |
| 2723 | Some(change_ref::Kind::Hash(hash)) => { |
| 2724 | let mut bytes = [0u8; 32]; |
| 2725 | if hash.value.len() != 32 { |
| 2726 | return Err(domain_status( |
| 2727 | ErrorCode::InvalidArgument, |
| 2728 | "hash must be 32 bytes", |
| 2729 | )); |
| 2730 | } |
| 2731 | bytes.copy_from_slice(&hash.value); |
| 2732 | repo.unrecord(&atomic_core::types::Merkle(bytes), options) |
| 2733 | .map_err(repository_error)? |
| 2734 | } |
| 2735 | Some(change_ref::Kind::Sequence(_)) => { |
| 2736 | return Err(domain_status( |
| 2737 | ErrorCode::InvalidArgument, |
| 2738 | "unrecord takes a hash target (or none for the last change)", |
| 2739 | )) |
| 2740 | } |
| 2741 | // Case-insensitive unique-prefix resolution over the whole |
| 2742 | // change store; the unrecord membership guard speaks. |
| 2743 | Some(change_ref::Kind::Prefix(prefix)) => { |
| 2744 | let prefix = prefix.trim().to_ascii_uppercase(); |
| 2745 | match repo.find_change_by_prefix(&prefix) { |
| 2746 | Ok(Some(hash)) => { |
| 2747 | repo.unrecord(&hash, options).map_err(repository_error)? |
| 2748 | } |
| 2749 | Ok(None) => { |
| 2750 | return Err(domain_status( |
| 2751 | ErrorCode::NotFound, |
| 2752 | format!("no change found matching '{prefix}'"), |
| 2753 | )) |
| 2754 | } |
| 2755 | Err(atomic_repository::RepositoryError::AmbiguousHash { |
| 2756 | prefix, |
| 2757 | matches, |
| 2758 | }) => { |
| 2759 | return Err(domain_status( |
| 2760 | ErrorCode::NotFound, |
no test coverage detected