MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / preview_restore

Method preview_restore

libatomic/src/daemon/services.rs:803–898  ·  view source on GitHub ↗
(
        &self,
        request: Request<PreviewRestoreRequest>,
    )

Source from the content-addressed store, hash-verified

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

Callers 1

callMethod · 0.45

Calls 15

domain_statusFunction · 0.85
default_refFunction · 0.85
componentsMethod · 0.80
as_refMethod · 0.80
log_rpcMethod · 0.80
entriesMethod · 0.80
get_file_contentMethod · 0.80
enter_workspaceFunction · 0.70
into_innerMethod · 0.45
is_emptyMethod · 0.45
resolveMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected