diff options
Diffstat (limited to 'src/access/rules.rs')
| -rw-r--r-- | src/access/rules.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/access/rules.rs b/src/access/rules.rs index c84adc9..1df1d58 100644 --- a/src/access/rules.rs +++ b/src/access/rules.rs @@ -98,6 +98,9 @@ pub(crate) struct Reads { /// Whether the document's own policy, at its heads then, is strict /// (`before_strict`): kept across `seen`, read again once the document takes more. strict_now: Option<(Vec<ChangeHash>, bool)>, + /// The changes that turned the document strict, at its heads then (`turned_strict`): + /// kept as `strict_now` is. + turned_now: Option<(Vec<ChangeHash>, Vec<ChangeHash>)>, } impl Reads { @@ -107,6 +110,7 @@ impl Reads { *self = Self { seen: seen.to_vec(), strict_now: self.strict_now.take(), + turned_now: self.turned_now.take(), ..Self::default() }; } @@ -125,6 +129,15 @@ impl Reads { } } } + + /// The changes that turned `doc` strict (`turned_strict`): found once for its heads. + fn turned_now(&mut self, doc: &Document) -> &[ChangeHash] { + let heads = doc.get_heads(); + if self.turned_now.as_ref().is_none_or(|(at, _)| *at != heads) { + self.turned_now = Some((heads, turned_strict(doc))); + } + &self.turned_now.as_ref().expect("just found").1 + } } impl Reads { @@ -179,7 +192,7 @@ pub(crate) fn judge_reading( .clone(); if !policy.strict() && reads.strict_now(doc) - && let Some(why) = before_strict(doc, change) + && let Some(why) = before_strict(doc, change, reads.turned_now(doc)) { return Err(Refusal::Rule(why)); } @@ -378,10 +391,10 @@ pub(crate) fn judge_reading( /// not, is refused like any other, so a change made later to look as old can't take its /// place. A swarm strict from its genesis change (`--bootstrap-policy`) has no such /// time. Asked only where `doc`'s policy is strict: elsewhere, nothing changes. -fn before_strict(doc: &Document, change: &Change<'_>) -> Option<String> { +fn before_strict(doc: &Document, change: &Change<'_>, turned: &[ChangeHash]) -> Option<String> { let held = crate::document::changes::holds(doc, &change.hash); - let beside = turned_strict(doc).into_iter().find(|turned| { - *turned != change.hash + let beside = turned.iter().find(|turned| { + **turned != change.hash && !in_history(doc, turned, change.deps) && !(held && in_history(doc, &change.hash, std::slice::from_ref(turned))) })?; @@ -399,9 +412,10 @@ fn turned_strict(doc: &Document) -> Vec<ChangeHash> { let strict_at = |heads: &[ChangeHash]| { At::new(doc, heads).is_some_and(|at| super::policy::of(&at).strict()) }; + let made = store::made(doc); let mut turned = Vec::new(); let mut looked: HashSet<ChangeHash> = HashSet::new(); - let mut writes = store::writers(doc, doc, &path); + let mut writes = store::writers(&made, doc, &path); while let Some((hash, deps)) = writes.pop() { if !looked.insert(hash) { continue; @@ -410,7 +424,7 @@ fn turned_strict(doc: &Document) -> Vec<ChangeHash> { turned.push(hash); } if let Some(before) = At::new(doc, &deps) { - writes.extend(store::writers(doc, &before, &path)); + writes.extend(store::writers(&made, &before, &path)); } } turned |
