Browse Source

fix env settings on apps load

Namdak Tonpa 8 years ago
parent
commit
2382a0abf3
3 changed files with 13 additions and 23 deletions
  1. 1 1
      include/mad.hrl
  2. BIN
      mad
  3. 12 22
      src/provision/mad_repl.erl

+ 1 - 1
include/mad.hrl

@@ -1 +1 @@
--define(VERSION,"419450").
+-define(VERSION,"41140c").

BIN
mad


+ 12 - 22
src/provision/mad_repl.erl

@@ -28,28 +28,16 @@ parse_applist(AppList) ->
 
 
 load_config() ->
 load_config() ->
    Config = wildcards(["sys.config",lists:concat(["etc/",mad:host(),"/sys.config"])]),
    Config = wildcards(["sys.config",lists:concat(["etc/",mad:host(),"/sys.config"])]),
-   Apps = case Config of
+   _Apps = case Config of
         [] -> case mad_repl:load_file("sys.config") of
         [] -> case mad_repl:load_file("sys.config") of
               {error,_} -> [];
               {error,_} -> [];
               {ok,Bin} -> parse(unicode:characters_to_list(Bin)) end;
               {ok,Bin} -> parse(unicode:characters_to_list(Bin)) end;
       File -> case file:consult(hd(File)) of
       File -> case file:consult(hd(File)) of
               {error,_} -> [];
               {error,_} -> [];
-              {ok,[A]} -> A end end,
-    load_config(Apps, []).
-
-load_config([H|T], Apps2) ->
-    App2 = case H of
-        {App,Cfg} -> [application:set_env(App,K,V) || {K,V} <- Cfg], [H];
-        File when is_list(File) ->
-            Apps = case file:consult(File) of
-                {error,_} -> [];
-                {ok,[A]} -> A end,
-            load_config(Apps, []);
-        _ -> []
-    end,
-    load_config(T, Apps2 ++ App2);
-load_config([], Apps2) ->
-    Apps2.
+              {ok,[A]} -> A end end.
+
+load_config(AppConfigs,[]) ->
+    [ [application:set_env(App,K,V) || {K,V} <- Cfg] || {App,Cfg} <- AppConfigs].
 
 
 acc_start(A,Acc) ->
 acc_start(A,Acc) ->
    case application:start(A) of
    case application:start(A) of
@@ -59,12 +47,14 @@ acc_start(A,Acc) ->
          ok -> Acc;
          ok -> Acc;
          _  -> Acc end.
          _  -> Acc end.
 
 
-load_apps([],_,_Acc) ->
+load_apps([],Config,_Acc) ->
   Res = lists:foldl(fun(A,Acc) -> case lists:member(A,system()) of
   Res = lists:foldl(fun(A,Acc) -> case lists:member(A,system()) of
        true -> acc_start(A,Acc);
        true -> acc_start(A,Acc);
-          _ -> case load_config(A) of
+          _ -> X = load_config(A),
+               case X of
                     [] -> acc_start(A,Acc);
                     [] -> acc_start(A,Acc);
                     _E -> acc_start(_E,Acc) end end end,[], applist()),
                     _E -> acc_start(_E,Acc) end end end,[], applist()),
+  load_config(Config,[]),
   case Res of
   case Res of
        [] -> ok;
        [] -> ok;
        _ -> mad:info("~nApps couldn't be loaded: ~p~n",[Res]) end;
        _ -> mad:info("~nApps couldn't be loaded: ~p~n",[Res]) end;
@@ -83,7 +73,7 @@ sh(Params) ->
     load(),
     load(),
     Config = load_config(),
     Config = load_config(),
     Driver = mad_utils:get_value(shell_driver,_Config,user_drv),
     Driver = mad_utils:get_value(shell_driver,_Config,user_drv),
-    repl_intro(),
+    repl_intro(Config),
     case os:type() of
     case os:type() of
          {win32,nt} -> os:cmd("chcp 65001"), shell:start();
          {win32,nt} -> os:cmd("chcp 65001"), shell:start();
                   _ -> O = whereis(user),
                   _ -> O = whereis(user),
@@ -168,7 +158,7 @@ parse(String) ->
     {value,Value,_Bs} = erl_eval:exprs(AbsForm, erl_eval:new_bindings()),
     {value,Value,_Bs} = erl_eval:exprs(AbsForm, erl_eval:new_bindings()),
     Value.
     Value.
 
 
-repl_intro() ->
-    io:format("Configuration: ~p~n", [load_config()]),
+repl_intro(Config) ->
+    io:format("Configuration: ~p~n", [Config]),
     io:format("Applications:  ~p~n", [applist()]).
     io:format("Applications:  ~p~n", [applist()]).