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

Method restore

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

Source from the content-addressed store, hash-verified

2002 }
2003
2004 async fn restore(
2005 &self,
2006 request: Request<RestoreRequest>,
2007 ) -> Result<Response<RestoreResponse>, Status> {
2008 let request = request.into_inner();
2009 let handle = self
2010 .state
2011 .resolve(request.repository.as_ref().unwrap_or(&default_ref()))?;
2012 self.state.log_rpc("Restore", Some(&handle));
2013 let gate_handle = handle.clone();
2014 let _gate = gate_handle.exclusive().await;
2015 let result = tokio::task::spawn_blocking(move || -> Result<RestoreResponse, Status> {
2016 let (repo, workspace) =
2017 handle.workspace_repository(atomic_repository::WorkspaceTxnMode::Reconcile)?;
2018 let working_copy = workspace.working_copy();
2019 // Restore only ever touches TRACKED dirty files — the
2020 // untracked scan is skipped (the CLI's status_options).
2021 // One status pass classifies every path; only tracked
2022 // dirty states (Modified/Deleted/Added) are considered.
2023 let status = repo
2024 .status(
2025 working_copy,
2026 StatusOptions {
2027 include_untracked: false,
2028 ..StatusOptions::default()
2029 },
2030 )
2031 .map_err(repository_error)?;
2032 let dirty: Vec<(String, atomic_repository::status::FileStatus)> = status
2033 .entries()
2034 .iter()
2035 .map(|e| (e.path().to_string_lossy().to_string(), e.status()))
2036 .filter(|(path, file_status)| {
2037 matches!(
2038 file_status,
2039 atomic_repository::status::FileStatus::Modified
2040 | atomic_repository::status::FileStatus::Deleted
2041 | atomic_repository::status::FileStatus::Added
2042 | atomic_repository::status::FileStatus::TypeChanged
2043 | atomic_repository::status::FileStatus::PermissionsChanged
2044 ) && (request.paths.is_empty()
2045 || request.paths.iter().any(|p| path.starts_with(p.as_str())))
2046 })
2047 .collect();
2048 // The CLI's safety gate: only a WHOLE-copy restore (no
2049 // paths) requires force; naming paths is explicit consent.
2050 if request.paths.is_empty() && !dirty.is_empty() && !request.force {
2051 return Err(domain_status(
2052 ErrorCode::PreconditionFailed,
2053 "restore: working copy has unrecorded changes — \
2054 name paths explicitly or pass force",
2055 ));
2056 }
2057 // One projection decides which Modified/Deleted paths the view
2058 // still records; rendering every file here only to discard the
2059 // bytes would decode the view's history once per file. A
2060 // projection error therefore fails the request before any path is
2061 // untracked, and a render error now surfaces from materialization

Callers

nothing calls this directly

Calls 15

default_refFunction · 0.85
domain_statusFunction · 0.85
name_conflict_errorFunction · 0.85
as_refMethod · 0.80
log_rpcMethod · 0.80
exclusiveMethod · 0.80
workspace_repositoryMethod · 0.80
entriesMethod · 0.80
repository_errorFunction · 0.70
removeMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected