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

Function check_view_fence

libatomic/src/daemon/services.rs:1235–1278  ·  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

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