From 369a6b7a47fe8a509a3d9112c3aaa04001431b3f Mon Sep 17 00:00:00 2001 From: Fang Date: Sat, 25 Sep 2021 00:54:24 +0400 Subject: [PATCH] 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. --- bin/solid.pill | 4 ++-- pkg/arvo/sys/vane/eyre.hoon | 41 +++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/bin/solid.pill b/bin/solid.pill index f1abb8a757..12c0234ad4 100644 --- a/bin/solid.pill +++ b/bin/solid.pill @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4e075d6c51dc81db5831da7ec1c0ea78140fc6e0d0f27f681097a96f7254dee1 -size 12469200 +oid sha256:99ac1fbddddaad25d3275d1308f5f3814f4e586501fb0233915b8191c8221415 +size 12589812 diff --git a/pkg/arvo/sys/vane/eyre.hoon b/pkg/arvo/sys/vane/eyre.hoon index e1e291ac0a..d4ae90e57a 100644 --- a/pkg/arvo/sys/vane/eyre.hoon +++ b/pkg/arvo/sys/vane/eyre.hoon @@ -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] - :: - $(to-search t.to-search) - :- & - :: store in reverse alphabetical order so that longer paths are first + |= $: new=[=binding =duct =action] + bindings=(list [=binding =duct =action]) + == + ^+ bindings + ?~ bindings [new]~ + =* bid binding.i.bindings + :: replace already bound paths :: - %- flop - %+ sort [[binding duct action] bindings] - |= [[a=^binding *] [b=^binding *]] + ?: =([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. :: - ?: =(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]