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
oid sha256:4e075d6c51dc81db5831da7ec1c0ea78140fc6e0d0f27f681097a96f7254dee1
size 12469200
oid sha256:99ac1fbddddaad25d3275d1308f5f3814f4e586501fb0233915b8191c8221415
size 12589812

View File

@ -1974,9 +1974,9 @@
?=([%'~_~' *] path.binding) :: runtime
==
[| bindings.state]
(insert-binding [binding duct action] bindings.state)
[& (insert-binding [binding duct action] bindings.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
@ -2097,28 +2097,29 @@
|= url=@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)) [[~ ~] ~])
:: +insert-binding: add a new binding, replacing any existing at its path
::
++ insert-binding
|= [[=binding =duct =action] bindings=(list [=binding =duct =action])]
=/ to-search bindings
|- ^- [? _bindings]
?^ to-search
?: =(binding binding.i.to-search)
[| bindings]
|= $: new=[=binding =duct =action]
bindings=(list [=binding =duct =action])
==
^+ bindings
?~ bindings [new]~
=* bid binding.i.bindings
:: replace already bound paths
::
$(to-search t.to-search)
:- &
:: store in reverse alphabetical order so that longer paths are first
?: =([site path]:bid [site path]:binding.new)
~> %slog.[0 leaf+"eyre: replacing existing binding at {<`path`path.bid>}"]
[new t.bindings]
:: if new comes before bid, prepend it.
:: otherwise, continue our search.
::
%- flop
%+ sort [[binding duct action] bindings]
|= [[a=^binding *] [b=^binding *]]
::
?: =(site.a site.b)
(aor path.a path.b)
:: alphabetize based on site
::
(aor ?~(site.a '' u.site.a) ?~(site.b '' u.site.b))
=; new-before-bid=?
?: new-before-bid [new bindings]
[i.bindings $(bindings t.bindings)]
?: =(site.binding.new site.bid)
(aor path.binding.new path.bid)
(aor (fall site.binding.new '') (fall site.bid ''))
::
++ channel-wire
|= [channel-id=@t request-id=@ud]