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

Function check_view_fence

libatomic/src/daemon/services.rs:1234–1277  ·  view source on GitHub ↗

Refuse unless `view` is at the state `expected` names — the write-path fence shared by insert, promote and the vault writes, checked inside the repository gate so the compare-and-write is one serialized step. The snapshot's `own_merkle` compares against the view's own root (the state a log read reports); its `effective_state` against the view's effective state (what it sees through its parent chai

(
    repo: &atomic_repository::Repository,
    view: &str,
    expected: &ViewSnapshot,
)

Source from the content-addressed store, hash-verified

1232/// a log read reports); its `effective_state` against the view's effective
1233/// state (what it sees through its parent chain).
1234pub(crate) fn check_view_fence(
1235 repo: &atomic_repository::Repository,
1236 view: &str,
1237 expected: &ViewSnapshot,
1238) -> Result<(), Status> {
1239 let named = expected
1240 .view
1241 .as_ref()
1242 .and_then(|view| view.name.clone())
1243 .unwrap_or_else(|| view.to_string());
1244 if named != view {
1245 return Err(domain_status(
1246 ErrorCode::ViewStale,
1247 format!("the fence names view '{named}' but the write targets '{view}'"),
1248 ));
1249 }
1250 let stale = |saw: String, at: String| {
1251 domain_status(
1252 ErrorCode::ViewStale,
1253 format!("view '{view}' has moved on (expected {saw}, at {at}) — re-read and try again"),
1254 )
1255 };
1256 match (&expected.own_merkle, &expected.effective_state) {
1257 (Some(saw), _) => {
1258 let saw = hash_from_proto(Some(saw))
1259 .map_err(|error| domain_status(ErrorCode::InvalidArgument, error))?;
1260 let at = repo.get_view_info(view).map_err(repository_error)?.state;
1261 if saw != at {
1262 return Err(stale(saw.to_base32(), at.to_base32()));
1263 }
1264 }
1265 (None, saw) => {
1266 let saw = hash_from_proto(saw.as_ref())
1267 .map_err(|error| domain_status(ErrorCode::InvalidArgument, error))?;
1268 let at = repo
1269 .sandbox_effective_state(view)
1270 .map_err(repository_error)?;
1271 if saw != at {
1272 return Err(stale(saw.to_base32(), at.to_base32()));
1273 }
1274 }
1275 }
1276 Ok(())
1277}
1278
1279/// A conflict is recorded state too: unchanged canonical markers may be
1280/// resolved by an insertion. Everything else keeps the dirty-worktree guard.

Callers 1

insert_changesMethod · 0.85

Calls 7

domain_statusFunction · 0.85
hash_from_protoFunction · 0.85
as_refMethod · 0.80
get_view_infoMethod · 0.80
cloneMethod · 0.45
to_base32Method · 0.45

Tested by

no test coverage detected