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

Method restore

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

Source from the content-addressed store, hash-verified

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