diff options
author | Matthias Radestock <matthias@lshift.net> | 2009-06-02 10:44:01 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@lshift.net> | 2009-06-02 10:44:01 +0100 |
commit | 08299fba892f017fc98ccb31c43a6fafc1583809 (patch) | |
tree | 931543d5aac39993318857a02e77deb9e9004820 | |
parent | 48614ecb2defab39d393dcea9517cc68686d144a (diff) | |
download | rabbitmq-server-08299fba892f017fc98ccb31c43a6fafc1583809.tar.gz |
make delete_binding return an error when the binding does not existbug20633
This required some refactoring in order to avoid duplication of the code
that constructs #binding records.
-rw-r--r-- | src/rabbit_exchange.erl | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index d6d70cba..21f219ae 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -381,32 +381,40 @@ call_with_exchange_and_queue(Exchange, Queue, Fun) -> end). add_binding(ExchangeName, QueueName, RoutingKey, Arguments) -> - call_with_exchange_and_queue( - ExchangeName, QueueName, - fun (X, Q) -> + binding_action( + ExchangeName, QueueName, RoutingKey, Arguments, + fun (X, Q, B) -> if Q#amqqueue.durable and not(X#exchange.durable) -> {error, durability_settings_incompatible}; - true -> ok = sync_binding( - ExchangeName, QueueName, RoutingKey, Arguments, - Q#amqqueue.durable, fun mnesia:write/3) + true -> ok = sync_binding(B, Q#amqqueue.durable, + fun mnesia:write/3) end end). delete_binding(ExchangeName, QueueName, RoutingKey, Arguments) -> + binding_action( + ExchangeName, QueueName, RoutingKey, Arguments, + fun (X, Q, B) -> + case mnesia:match_object(rabbit_route, #route{binding = B}, + write) of + [] -> {error, binding_not_found}; + _ -> ok = sync_binding(B, Q#amqqueue.durable, + fun mnesia:delete_object/3), + maybe_auto_delete(X) + end + end). + +binding_action(ExchangeName, QueueName, RoutingKey, Arguments, Fun) -> call_with_exchange_and_queue( ExchangeName, QueueName, fun (X, Q) -> - ok = sync_binding( - ExchangeName, QueueName, RoutingKey, Arguments, - Q#amqqueue.durable, fun mnesia:delete_object/3), - maybe_auto_delete(X) + Fun(X, Q, #binding{exchange_name = ExchangeName, + queue_name = QueueName, + key = RoutingKey, + args = sort_arguments(Arguments)}) end). -sync_binding(ExchangeName, QueueName, RoutingKey, Arguments, Durable, Fun) -> - Binding = #binding{exchange_name = ExchangeName, - queue_name = QueueName, - key = RoutingKey, - args = sort_arguments(Arguments)}, +sync_binding(Binding, Durable, Fun) -> ok = case Durable of true -> Fun(rabbit_durable_route, #route{binding = Binding}, write); @@ -472,7 +480,7 @@ parse_x_match(Other) -> %% Horrendous matching algorithm. Depends for its merge-like %% (linear-time) behaviour on the lists:keysort (sort_arguments) that -%% route/3 and sync_binding/6 do. +%% route/3 and {add,delete}_binding/4 do. %% %% !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! %% In other words: REQUIRES BOTH PATTERN AND DATA TO BE SORTED ASCENDING BY KEY. |