@@ -124,8 +124,6 @@ exists(Binding) ->
124
124
125
125
add (Binding ) -> add (Binding , fun (_Src , _Dst ) -> ok end ).
126
126
127
- remove (Binding ) -> remove (Binding , fun (_Src , _Dst ) -> ok end ).
128
-
129
127
add (Binding , InnerFun ) ->
130
128
binding_action (
131
129
Binding ,
@@ -134,56 +132,46 @@ add(Binding, InnerFun) ->
134
132
% % in general, we want to fail on that in preference to
135
133
% % anything else
136
134
case InnerFun (Src , Dst ) of
137
- ok -> add (Src , Dst , B );
135
+ ok -> case mnesia :read ({rabbit_route , B }) of
136
+ [] -> add (Src , Dst , B );
137
+ [_ ] -> fun rabbit_misc :const_ok /1
138
+ end ;
138
139
{error , _ } = Err -> rabbit_misc :const (Err )
139
140
end
140
141
end ).
141
142
142
143
add (Src , Dst , B ) ->
143
- case mnesia :read ({rabbit_route , B }) of
144
- [] -> Durable = all_durable ([Src , Dst ]),
145
- case (not Durable orelse
146
- mnesia :read ({rabbit_durable_route , B }) =:= []) of
147
- true -> ok = sync_binding (B , Durable , fun mnesia :write /3 ),
148
- fun (Tx ) ->
149
- ok = rabbit_exchange :callback (
150
- Src , add_binding , [Tx , Src , B ]),
151
- rabbit_event :notify_if (
152
- not Tx , binding_created , info (B ))
153
- end ;
154
- false -> rabbit_misc :const (not_found )
155
- end ;
156
- [_ ] -> fun rabbit_misc :const_ok /1
144
+ Durable = all_durable ([Src , Dst ]),
145
+ case (not Durable orelse mnesia :read ({rabbit_durable_route , B }) =:= []) of
146
+ true -> ok = sync_binding (B , Durable , fun mnesia :write /3 ),
147
+ fun (Tx ) -> ok = rabbit_exchange :callback (Src , add_binding ,
148
+ [Tx , Src , B ]),
149
+ rabbit_event :notify_if (not Tx , binding_created ,
150
+ info (B ))
151
+ end ;
152
+ false -> rabbit_misc :const (not_found )
157
153
end .
158
154
155
+ remove (Binding ) -> remove (Binding , fun (_Src , _Dst ) -> ok end ).
156
+
159
157
remove (Binding , InnerFun ) ->
160
158
binding_action (
161
159
Binding ,
162
160
fun (Src , Dst , B ) ->
163
- Result =
164
- case mnesia :match_object (rabbit_route , # route {binding = B },
165
- write ) of
166
- [] ->
167
- {error , binding_not_found };
168
- [_ ] ->
169
- case InnerFun (Src , Dst ) of
170
- ok ->
171
- ok = sync_binding (B , all_durable ([Src , Dst ]),
172
- fun mnesia :delete_object /3 ),
173
- {ok , maybe_auto_delete (B # binding .source ,
174
- [B ], new_deletions ())};
175
- {error , _ } = E ->
176
- E
177
- end
178
- end ,
179
- case Result of
180
- {error , _ } = Err ->
181
- rabbit_misc :const (Err );
182
- {ok , Deletions } ->
183
- fun (Tx ) -> ok = process_deletions (Deletions , Tx ) end
161
+ case mnesia :read (rabbit_route , B , write ) of
162
+ [] -> rabbit_misc :const ({error , binding_not_found });
163
+ [_ ] -> case InnerFun (Src , Dst ) of
164
+ ok -> remove (Src , Dst , B );
165
+ {error , _ } = Err -> rabbit_misc :const (Err )
166
+ end
184
167
end
185
168
end ).
186
169
170
+ remove (Src , Dst , B ) ->
171
+ ok = sync_binding (B , all_durable ([Src , Dst ]), fun mnesia :delete_object /3 ),
172
+ Deletions = maybe_auto_delete (B # binding .source , [B ], new_deletions ()),
173
+ fun (Tx ) -> ok = process_deletions (Deletions , Tx ) end .
174
+
187
175
list (VHostPath ) ->
188
176
VHostResource = rabbit_misc :r (VHostPath , '_' ),
189
177
Route = # route {binding = # binding {source = VHostResource ,
0 commit comments