Skip to content

Commit 9aedff7

Browse files
committed
Try to make setup more in tune with zomp
1 parent d9b0b51 commit 9aedff7

2 files changed

Lines changed: 20 additions & 26 deletions

File tree

src/setup.erl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,12 @@ home() ->
200200
home_(Vis) ->
201201
case get_env_v(setup, home, Vis) of
202202
undefined ->
203-
CWD = cwd(),
204-
D = filename:absname(CWD),
203+
Dir = default_dir(home),
204+
D = filename:absname(Dir),
205205
application:set_env(setup, home, D),
206206
D;
207-
{ok, D} when is_binary(D) ->
208-
binary_to_list(D);
209-
{ok, D} when is_list(D) ->
210-
D;
207+
{ok, D} ->
208+
unicode:characters_to_list(D);
211209
{error,_} = Error ->
212210
Error;
213211
Other ->
@@ -246,6 +244,7 @@ default_dir(Type) ->
246244
setup_default_dir(Type)
247245
end.
248246

247+
setup_default_dir(home) -> cwd();
249248
setup_default_dir(log) -> "log." ++ atom_to_list(node());
250249
setup_default_dir(data) -> "data." ++ atom_to_list(node()).
251250

@@ -457,7 +456,7 @@ expand_env(_, {T,"$env(" ++ S} = X, A, Vis)
457456
{undefined, '$string'} -> "";
458457
{undefined, '$binary'} -> <<>>;
459458
{{ok,V} , '$value'} -> V;
460-
{{ok,V} , '$string'} -> binary_to_list(stringify(V));
459+
{{ok,V} , '$string'} -> unicode:characters_to_list(stringify(V));
461460
{{ok,V} , '$binary'} -> stringify(V)
462461
end
463462
catch
@@ -731,8 +730,8 @@ find_app(A, LibDirs) ->
731730

732731
to_string(A) when is_atom(A) ->
733732
atom_to_list(A);
734-
to_string(A) when is_list(A) ->
735-
A.
733+
to_string(A) when is_list(A); is_binary(A) ->
734+
unicode:characters_to_list(A).
736735

737736
is_app_dir(AStr, D) ->
738737
Pat = AStr ++ "(-[0-9]+(\\..+)?)?/ebin\$",

src/setup_zomp.erl

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,23 @@ update_env() ->
1515
?LOG_INFO("Plain args: ~p", [Args]),
1616
look_for_setup_env(Args).
1717

18-
default_dir(data) ->
19-
#{package_id := PId} = zx_daemon:meta(),
20-
Dir = zx_lib:ppath(var, PId),
21-
filename:join(Dir, "setup.data");
18+
default_dir(home) -> ppath(etc);
19+
default_dir(data) -> ppath(var);
2220
default_dir(log) ->
23-
try zomp_default_log_dir()
24-
catch
25-
error:_ ->
26-
undefined
27-
end.
21+
Dir = ppath(log),
22+
filename:join(Dir, "log").
23+
24+
ppath(Type) ->
25+
zx_lib:ppath(Type, package_id()).
26+
27+
package_id() ->
28+
#{package_id := PId} = zx_daemon:meta(),
29+
PId.
2830

2931
setup_conf_path() ->
30-
#{package_id := TopPId} = zx_daemon:meta(),
31-
TopPPath = zx_lib:ppath(lib, TopPId),
32+
TopPPath = ppath(lib),
3233
[".", TopPPath].
3334

34-
zomp_default_log_dir() ->
35-
{ok, H} = logger:get_handler_config(default),
36-
#{config := #{file := F}} = H,
37-
[Base,_] = re:split(F,"\\.log$",[{return,list}]),
38-
Base.
39-
4035
look_for_setup_env(["-setup", K, V | Rest]) ->
4136
?LOG_INFO("Processing env: ~p ~p", [K, V]),
4237
process_env(K, V),

0 commit comments

Comments
 (0)