diff options
| author | tv <tv@krebsco.de> | 2026-11-16 10:38:26 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-16 10:38:26 +0000 |
| commit | 35ba6d49a673b4f34873486cfd521053c5e27971 (patch) | |
| tree | 24bb4af815b53a912138b3b828fb78ecaf93140b /src/document/store.rs | |
| parent | 8029b408b7e33bfd429c9b0cb2ac5412afda3bcc (diff) | |
screen: what is at the policy's place found in every map on the way
A node judges what it receives once anything is at the policy's place
(`Screening::policed`), as a read shows it. But a read shows the newest
of the values written at once at a key, merging maps only where that one
is a map: a string written at `_continuum/access` beside the map holding
the policy, and newer, hides it. So the policy's place read as empty,
a change putting `"signed"` into the hidden policy went unjudged where
it came alone, and deleting the string left a strict policy no change
was refused for.
Whether anything is at the policy's place is asked of every map of each
key on the way to it, read or not (`store::held_anywhere`), as
`store::by_seq` walks them. A swarm with nothing there is screened as
before.
Diffstat (limited to 'src/document/store.rs')
| -rw-r--r-- | src/document/store.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/document/store.rs b/src/document/store.rs index cd455b6..7de7373 100644 --- a/src/document/store.rs +++ b/src/document/store.rs @@ -654,6 +654,29 @@ pub(crate) fn read_path_with_conflicts_as( Ok(value.map(|value| (value, log.reports))) } +/// Whether anything is at `path` (map keys only) in any of the values written at once on +/// the way to it, not only those a read shows: of every key, every map among its values, +/// then the key itself (as `by_seq` walks them). A read shows the newest value of a key, +/// merging maps only where that one is a map, so a value beside a map hides what is in it. +pub(crate) fn held_anywhere(doc: &impl ReadDoc, path: &[String]) -> bool { + let Some((last, way)) = path.split_last() else { + return true; + }; + let mut maps = vec![automerge::ROOT]; + for step in way { + maps = maps + .iter() + .flat_map(|map| doc.get_all(map, step.as_str()).unwrap_or_default()) + .filter_map(|(value, id)| matches!(value, Value::Object(ObjType::Map)).then_some(id)) + .collect(); + } + maps.iter().any(|map| { + !doc.get_all(map, last.as_str()) + .unwrap_or_default() + .is_empty() + }) +} + /// What is stored at `path` (the empty path: the root map), and, where it is a scalar /// or a text, the value itself, to show natively (`typed::native`); None if nothing is /// there. |
