Skip to content

Commit 222ac74

Browse files
author
Simon MacMullen
committed
Make add and delete more symmetrical, tidy up a bit.
1 parent 682d46f commit 222ac74

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/rabbit_exchange.erl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -428,25 +428,25 @@ add_binding(ExchangeName, QueueName, RoutingKey, Arguments, InnerFun) ->
428428
%% in general, we want to fail on that in preference to
429429
%% anything else
430430
case InnerFun(X, Q) of
431-
{error, _} = E -> E;
432-
_ ->
431+
ok ->
433432
case mnesia:read({rabbit_route, B}) of
434433
[] ->
435-
sync_binding(B,
436-
X#exchange.durable andalso
437-
Q#amqqueue.durable,
438-
fun mnesia:write/3),
434+
ok = sync_binding(B,
435+
X#exchange.durable andalso
436+
Q#amqqueue.durable,
437+
fun mnesia:write/3),
439438
{new, X, B};
440439
[_R] ->
441440
{existing, X, B}
442-
end
441+
end;
442+
{error, _} = E -> E
443443
end
444444
end) of
445445
{new, Exchange = #exchange{ type = Type }, Binding} ->
446446
(type_to_module(Type)):add_binding(Exchange, Binding);
447447
{existing, _, _} ->
448448
ok;
449-
Err = {error, _} ->
449+
{error, _} = Err ->
450450
Err
451451
end.
452452

@@ -459,16 +459,18 @@ delete_binding(ExchangeName, QueueName, RoutingKey, Arguments, InnerFun) ->
459459
[] -> {error, binding_not_found};
460460
_ ->
461461
case InnerFun(X, Q) of
462-
{error, _} = E -> E;
463-
_ ->
462+
ok ->
464463
ok =
465-
sync_binding(B, Q#amqqueue.durable,
464+
sync_binding(B,
465+
X#exchange.durable andalso
466+
Q#amqqueue.durable,
466467
fun mnesia:delete_object/3),
467-
{maybe_auto_delete(X), B}
468+
{maybe_auto_delete(X), B};
469+
{error, _} = E -> E
468470
end
469471
end
470472
end) of
471-
Err = {error, _} ->
473+
{error, _} = Err ->
472474
Err;
473475
{{IsDeleted, X = #exchange{ type = Type }}, B} ->
474476
Module = type_to_module(Type),

0 commit comments

Comments
 (0)