fix plugins code bug

This commit is contained in:
Feng Lee 2015-08-08 18:47:04 +08:00
parent c6ccacd990
commit 0f602d67ba
2 changed files with 10 additions and 6 deletions

View File

@ -184,14 +184,14 @@ plugins(["list"]) ->
plugins(["load", Name]) ->
case emqttd_plugins:load(list_to_atom(Name)) of
{ok, StartedApps} -> ?PRINT("start apps: ~p, plugin ~s is loaded successfully.~n", [StartedApps, Name]);
{error, Reason} -> ?PRINT("load plugin error: ~s~n", [Reason])
{ok, StartedApps} -> ?PRINT("Start apps: ~p~nPlugin ~s loaded successfully.~n", [StartedApps, Name]);
{error, Reason} -> ?PRINT("load plugin error: ~p~n", [Reason])
end;
plugins(["unload", Name]) ->
case emqttd_plugins:unload(list_to_atom(Name)) of
ok -> ?PRINT("plugin ~s is unloaded successfully.~n", [Name]);
{error, Reason} -> ?PRINT("unload plugin error: ~s~n", [Reason])
ok -> ?PRINT("Plugin ~s unloaded successfully.~n", [Name]);
{error, Reason} -> ?PRINT("unload plugin error: ~p~n", [Reason])
end.
trace(["list"]) ->

View File

@ -157,6 +157,8 @@ load_app(App, Config) ->
case application:load(App) of
ok ->
set_config(Config);
{error, {already_loaded, App}} ->
set_config(Config);
{error, Error} ->
{error, Error}
end.
@ -241,7 +243,7 @@ plugin_loaded(Name, true) ->
case lists:member(Name, Names) of
false ->
%% write file if plugin is loaded
write_loaded(lists:append(Names, Name));
write_loaded(lists:append(Names, [Name]));
true ->
ignore
end;
@ -272,12 +274,14 @@ read_loaded(File) ->
file:consult(File).
write_loaded(AppNames) ->
case file:open(env(loaded_file), [binary, write]) of
{ok, File} = env(loaded_file),
case file:open(File, [binary, write]) of
{ok, Fd} ->
lists:foreach(fun(Name) ->
file:write(Fd, iolist_to_binary(io_lib:format("~s.~n", [Name])))
end, AppNames);
{error, Error} ->
lager:error("Open File ~p Error: ~p", [File, Error]),
{error, Error}
end.