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

Method submit_recorded

atomic-repository/src/repository/remote_cache.rs:964–1014  ·  view source on GitHub ↗

In a remote sandbox, what applying a recorded change means: hand it to the owner, and take the view as it is once it lands. A refusal that says the view moved on is not a dead end: the owner sends the view as it is now, and the cache takes it, so the next `record` is computed against the graph this one was refused for. The change that was refused is not applied — the caller has to record it again

(
        &self,
        outcome: &crate::record::RecordOutcome,
    )

Source from the content-addressed store, hash-verified

962 /// change that was refused is not applied — the caller has to record it
963 /// again — and the error says so.
964 pub(crate) fn submit_recorded(
965 &self,
966 outcome: &crate::record::RecordOutcome,
967 ) -> Result<crate::InsertOutcome, RepositoryError> {
968 let bytes = outcome
969 .v3_bytes()
970 .ok_or_else(|| RepositoryError::Apply("the change has no bytes".to_string()))?
971 .to_vec();
972 let base_state = self.remote_sandbox_effective_state()?;
973 let (submitted, skeleton) = match link()?
974 .submit(&self.root, base_state, *outcome.hash(), bytes)
975 .map_err(|message| RepositoryError::InvalidOperation { message })?
976 {
977 Ok(landed) => landed,
978 Err((rejection, resync)) => {
979 if let Some(resync) = resync {
980 self.import_sandbox_skeleton(&resync)?;
981 // The rows are current now; the files on disk are not.
982 // Recording over them would read whatever landed
983 // underneath as this sandbox's own edits — a file
984 // another writer added reads as deleted here, and the
985 // next record would delete it from the view.
986 std::fs::write(self.dot_dir.join(BEHIND_MARKER), rejection.to_string())?;
987 }
988 return Err(RepositoryError::Apply(match rejection {
989 SubmitRejection::StaleView { .. } => {
990 "the repository refused the change: the view has moved on since this \
991 sandbox was materialized (VIEW_STALE); materialize it again \
992 (`atomic sandbox materialize`) and redo the edit"
993 .to_string()
994 }
995 rejection => format!("the repository refused the change: {rejection}"),
996 }));
997 }
998 };
999 self.import_sandbox_skeleton(&skeleton)?;
1000 self.hydrate_remote_sandbox()?;
1001 self.refresh_working_copy_desired_state(self.require_working_copy_id()?)?;
1002 let state =
1003 <Hash as atomic_core::types::Base32>::from_base32(submitted.state.as_bytes())
1004 .ok_or_else(|| RepositoryError::Apply("the owner sent a bad state".to_string()))?;
1005 let mut stats = crate::InsertStats::new();
1006 stats.changes_applied = 1;
1007 stats.applied_hashes.push(submitted.hash);
1008 Ok(crate::InsertOutcome::new(
1009 state,
1010 skeleton.view.change_count,
1011 false,
1012 stats,
1013 ))
1014 }
1015
1016 /// Serve side, once a sandbox's change `hash` has landed on `view`: the
1017 /// view's skeleton for the sandbox's cache, and — as a pull does for the

Callers 1

Calls 12

linkFunction · 0.85
v3_bytesMethod · 0.80
writeFunction · 0.50
submitMethod · 0.45
hashMethod · 0.45
as_bytesMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected