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

Method submit_recorded

atomic-repository/src/repository/remote_cache.rs:959–1009  ·  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

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