Reuse plugin filter logic to adapt to emqx rebar3 release

This commit is contained in:
Gilbert Wong 2019-05-06 12:33:43 +08:00 committed by Gilbert
parent b040d37a40
commit 3ece73b912
1 changed files with 9 additions and 5 deletions

View File

@ -108,13 +108,20 @@ ensure_file(File) ->
with_loaded_file(File, SuccFun) -> with_loaded_file(File, SuccFun) ->
case read_loaded(File) of case read_loaded(File) of
{ok, Names} -> {ok, Names0} ->
Names = filter_plugins(Names0),
SuccFun(Names); SuccFun(Names);
{error, Error} -> {error, Error} ->
?LOG(alert, "[Plugins] Failed to read: ~p, error: ~p", [File, Error]), ?LOG(alert, "[Plugins] Failed to read: ~p, error: ~p", [File, Error]),
{error, Error} {error, Error}
end. end.
filter_plugins(Names) ->
lists:filtermap(fun(Name1) when is_atom(Name1) -> {true, Name1};
({Name1, true}) -> {true, Name1};
({_Name1, false}) -> false
end, Names).
load_plugins(Names, Persistent) -> load_plugins(Names, Persistent) ->
Plugins = list(), NotFound = Names -- names(Plugins), Plugins = list(), NotFound = Names -- names(Plugins),
case NotFound of case NotFound of
@ -277,10 +284,7 @@ plugin_unloaded(_Name, false) ->
plugin_unloaded(Name, true) -> plugin_unloaded(Name, true) ->
case read_loaded() of case read_loaded() of
{ok, Names0} -> {ok, Names0} ->
Names = lists:filtermap(fun(Name1) when is_atom(Name1) -> {true, Name1}; Names = filter_plugins(Names0),
({Name1, true}) -> {true, Name1};
({_Name1, false}) -> false
end, Names0),
case lists:member(Name, Names) of case lists:member(Name, Names) of
true -> true ->
write_loaded(lists:delete(Name, Names)); write_loaded(lists:delete(Name, Names));