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

Method preview_restore

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

Source from the content-addressed store, hash-verified

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()))

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