Adapt for running from escript (fix 4).

This commit is contained in:
Anton Makarov
2025-09-10 14:53:06 +03:00
parent 204bdba2eb
commit 6b9bd3745c

View File

@@ -88,30 +88,24 @@ init() ->
%% @private %% @private
get_priv_dir() -> get_priv_dir() ->
PrivDir = code:priv_dir(esqlite), case is_escript() of
io:format("PrivDir = code:priv_dir(esqlite) = ~p~n", [PrivDir]), {true,Escript} ->
case PrivDir of io:format("Escript = ~p~n", [Escript]),
%case code:priv_dir(esqlite) of Which = code:which(esqlite),
{error, bad_name} -> io:format("Which = ~p~n", [Which]),
%% application isn't in path, fall back {Pref,Suf} = lists:split(erlang:length(Escript), Which),
case is_escript() of io:format("Pref = ~p~n", [Pref]),
{true,Escript} -> io:format("Suf = ~p~n", [Suf]),
io:format("Escript = ~p~n", [Escript]), RootDir = filename:dirname(filename:dirname(Pref)),
Which = code:which(esqlite), AppsDir = filename:join(RootDir, "lib"),
io:format("Which = ~p~n", [Which]), io:format("AppsDir = ~p~n", [AppsDir]),
{Pref,Suf} = lists:split(erlang:length(Escript), Which), SqDir = filename:dirname(filename:dirname(Suf)),
io:format("Pref = ~p~n", [Pref]), filename:join([AppsDir, [$.|SqDir], "priv"]); % prepend "." to suffix that starts with "/"
io:format("Suf = ~p~n", [Suf]), false ->
RootDir = filename:dirname(filename:dirname(Pref)), case code:priv_dir(esqlite) of
AppsDir = filename:join(RootDir, "lib"), {error, bad_name} -> "priv";
io:format("AppsDir = ~p~n", [AppsDir]), Dir -> Dir
SqDir = filename:dirname(filename:dirname(Suf)), end
filename:join([AppsDir, [$.|SqDir], "priv"]); % prepend "." to suffix that starts with "/"
false ->
"priv"
end;
Dir ->
Dir
end. end.
%% @private %% @private