Re-project the verified state selected by an earlier reachable operation.
(
&mut self,
working_copy: WorkingCopyId,
target: OperationId,
)
| 852 | |
| 853 | /// Re-project the verified state selected by an earlier reachable operation. |
| 854 | pub fn restore_operation( |
| 855 | &mut self, |
| 856 | working_copy: WorkingCopyId, |
| 857 | target: OperationId, |
| 858 | ) -> Result<OperationId, RepositoryError> { |
| 859 | let scope = OperationScope::WorkingCopy(working_copy); |
| 860 | let current_head = self.sole_operation_head(scope)?; |
| 861 | let history = self.operation_log(scope, None, false)?; |
| 862 | if !history |
| 863 | .entries |
| 864 | .iter() |
| 865 | .any(|entry| entry.operation.id() == target) |
| 866 | { |
| 867 | return Err(RepositoryError::OperationNotReachable { |
| 868 | operation: target.to_string(), |
| 869 | scope: scope.to_string(), |
| 870 | }); |
| 871 | } |
| 872 | let details = self.operation_details(target)?; |
| 873 | if details.verification != OperationVerificationState::Verified { |
| 874 | return Err(RepositoryError::OperationNotVerified { |
| 875 | operation: target.to_string(), |
| 876 | }); |
| 877 | } |
| 878 | if !details.operation.payload().delta.metadata.is_empty() { |
| 879 | return self.append_related_metadata_operation( |
| 880 | working_copy, |
| 881 | &details.operation, |
| 882 | OperationKind::Restore, |
| 883 | OperationRelation::Restore { target }, |
| 884 | false, |
| 885 | ); |
| 886 | } |
| 887 | let view = details |
| 888 | .operation |
| 889 | .payload() |
| 890 | .delta |
| 891 | .after |
| 892 | .view |
| 893 | .as_ref() |
| 894 | .map(|view| view.name.clone()) |
| 895 | .ok_or_else(|| { |
| 896 | operation_not_reversible( |
| 897 | &details.operation, |
| 898 | "the operation does not carry a selected view state", |
| 899 | ) |
| 900 | })?; |
| 901 | let expected_state = details |
| 902 | .operation |
| 903 | .payload() |
| 904 | .delta |
| 905 | .after |
| 906 | .view |
| 907 | .as_ref() |
| 908 | .map(|state| state.state) |
| 909 | .ok_or_else(|| { |
| 910 | operation_not_reversible( |
| 911 | &details.operation, |