(
&self,
request: Request<PreviewRestoreRequest>,
)
| 800 | } |
| 801 | |
| 802 | async fn preview_restore( |
| 803 | &self, |
| 804 | request: Request<PreviewRestoreRequest>, |
| 805 | ) -> Result<Response<PreviewMutationResponse>, Status> { |
| 806 | let request = request.into_inner(); |
| 807 | if let Some(path) = &request.content_path { |
| 808 | use std::path::Component; |
| 809 | if path.is_empty() |
| 810 | || std::path::Path::new(path).components().any(|component| { |
| 811 | matches!( |
| 812 | component, |
| 813 | Component::ParentDir | Component::RootDir | Component::Prefix(_) |
| 814 | ) |
| 815 | }) |
| 816 | { |
| 817 | return Err(domain_status( |
| 818 | ErrorCode::InvalidArgument, |
| 819 | "content_path must be repository-relative", |
| 820 | )); |
| 821 | } |
| 822 | } |
| 823 | let handle = self |
| 824 | .state |
| 825 | .resolve(request.repository.as_ref().unwrap_or(&default_ref()))?; |
| 826 | self.state.log_rpc("PreviewRestore", Some(&handle)); |
| 827 | // Read transaction: read-only open, never queued behind writers. |
| 828 | let root = handle.root.clone(); |
| 829 | let result = |
| 830 | tokio::task::spawn_blocking(move || -> Result<PreviewMutationResponse, Status> { |
| 831 | let mut repo = Repository::open_readonly(&root).map_err(|error| { |
| 832 | domain_status( |
| 833 | ErrorCode::Repository, |
| 834 | format!("failed to open repository read-only: {error}"), |
| 835 | ) |
| 836 | })?; |
| 837 | let workspace = super::state::enter_workspace( |
| 838 | &mut repo, |
| 839 | atomic_repository::WorkspaceTxnMode::Observe, |
| 840 | )?; |
| 841 | let working_copy = workspace.working_copy(); |
| 842 | // The Restore classification WITHOUT mutation: tracked-only |
| 843 | // status pass; Added files would be untracked (kept on |
| 844 | // disk), Modified/Deleted would be restored. |
| 845 | let status = repo |
| 846 | .status( |
| 847 | working_copy, |
| 848 | StatusOptions { |
| 849 | include_untracked: false, |
| 850 | ..StatusOptions::default() |
| 851 | }, |
| 852 | ) |
| 853 | .map_err(repository_error)?; |
| 854 | let mut affected: Vec<String> = Vec::new(); |
| 855 | let mut untracked: Vec<String> = Vec::new(); |
| 856 | for entry in status.entries() { |
| 857 | let path = entry.path().to_string_lossy().to_string(); |
| 858 | if !request.paths.is_empty() |
| 859 | && !request.paths.iter().any(|p| path.starts_with(p.as_str())) |
no test coverage detected