eyre: allow overwriting existing bindings

Previously, if trying to bind to an endpoint that was already bound to,
eyre would reject it. This doesn't play very nicely in a softdist world
where uninstalled apps might not get a chance to clean up, and apps
might re-bind simply for being re-installed.

Here we change eyre to overwrite an existing binding if it conflicts
with the new one to be added.
This commit is contained in:
Fang 2021-09-25 00:54:24 +04:00
parent b7750ff605
commit 369a6b7a47
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
2 changed files with 23 additions and 22 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:4e075d6c51dc81db5831da7ec1c0ea78140fc6e0d0f27f681097a96f7254dee1 oid sha256:99ac1fbddddaad25d3275d1308f5f3814f4e586501fb0233915b8191c8221415
size 12469200 size 12589812

View File

@ -1974,9 +1974,9 @@
?=([%'~_~' *] path.binding) :: runtime ?=([%'~_~' *] path.binding) :: runtime
== ==
[| bindings.state] [| bindings.state]
(insert-binding [binding duct action] bindings.state) [& (insert-binding [binding duct action] bindings.state)]
:_ state :_ state
[duct %give %bound success binding]~ [duct %give %bound & binding]~
:: +remove-binding: removes a binding if it exists and is owned by this duct :: +remove-binding: removes a binding if it exists and is owned by this duct
:: ::
++ remove-binding ++ remove-binding
@ -2097,28 +2097,29 @@
|= url=@t |= url=@t
^- [[ext=(unit @ta) site=(list @t)] args=(list [key=@t value=@t])] ^- [[ext=(unit @ta) site=(list @t)] args=(list [key=@t value=@t])]
(fall (rush url ;~(plug apat:de-purl:html yque:de-purl:html)) [[~ ~] ~]) (fall (rush url ;~(plug apat:de-purl:html yque:de-purl:html)) [[~ ~] ~])
:: +insert-binding: add a new binding, replacing any existing at its path
:: ::
++ insert-binding ++ insert-binding
|= [[=binding =duct =action] bindings=(list [=binding =duct =action])] |= $: new=[=binding =duct =action]
=/ to-search bindings bindings=(list [=binding =duct =action])
|- ^- [? _bindings] ==
?^ to-search ^+ bindings
?: =(binding binding.i.to-search) ?~ bindings [new]~
[| bindings] =* bid binding.i.bindings
:: replace already bound paths
:: ::
$(to-search t.to-search) ?: =([site path]:bid [site path]:binding.new)
:- & ~> %slog.[0 leaf+"eyre: replacing existing binding at {<`path`path.bid>}"]
:: store in reverse alphabetical order so that longer paths are first [new t.bindings]
:: if new comes before bid, prepend it.
:: otherwise, continue our search.
:: ::
%- flop =; new-before-bid=?
%+ sort [[binding duct action] bindings] ?: new-before-bid [new bindings]
|= [[a=^binding *] [b=^binding *]] [i.bindings $(bindings t.bindings)]
:: ?: =(site.binding.new site.bid)
?: =(site.a site.b) (aor path.binding.new path.bid)
(aor path.a path.b) (aor (fall site.binding.new '') (fall site.bid ''))
:: alphabetize based on site
::
(aor ?~(site.a '' u.site.a) ?~(site.b '' u.site.b))
:: ::
++ channel-wire ++ channel-wire
|= [channel-id=@t request-id=@ud] |= [channel-id=@t request-id=@ud]