Skip to content

Commit 49e6d13

Browse files
committed
fix: properly use XDG specs
Before setting `XDG_{CONFIG,CACHE}_HOME` didn't changed Rebar3 behaviour which would still, forcefully, use `$HOME/.config` and `$HOME/.cache` respectively. Now it will properly read these environment variables and work accordingly.
1 parent 6e79ef6 commit 49e6d13

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: src/rebar_dir.erl

+10-6
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,22 @@ home_dir() ->
133133
{ok, [[Home]]} = init:get_argument(home),
134134
Home.
135135

136+
basedir(Type) ->
137+
filename:basedir(Type, "rebar3", #{os => linux}).
138+
136139
%% @doc returns the directory where the global configuration files for rebar3
137140
%% may be stored.
138141
-spec global_config_dir(rebar_state:t()) -> file:filename_all().
139142
global_config_dir(State) ->
140-
filename:join([rebar_config_dir(State), ".config", "rebar3"]).
143+
case rebar_config_dir(State) of
144+
undefined -> basedir(user_config);
145+
Path -> filename:join([Path, ".config", "rebar3"])
146+
end.
141147

142148
rebar_config_dir(State) ->
143149
case os:getenv("REBAR_GLOBAL_CONFIG_DIR") of
144150
false ->
145-
rebar_state:get(State, global_rebar_dir, home_dir());
151+
rebar_state:get(State, global_rebar_dir, undefined);
146152
ConfDir ->
147153
ConfDir
148154
end.
@@ -155,14 +161,12 @@ global_config(State) ->
155161
%% @doc returns the default path of the global rebar.config file
156162
-spec global_config() -> file:filename_all().
157163
global_config() ->
158-
Home = home_dir(),
159-
filename:join([Home, ".config", "rebar3", "rebar.config"]).
164+
filename:join([basedir(user_config), "rebar.config"]).
160165

161166
%% @doc returns the location for the global cache directory
162167
-spec global_cache_dir(rebar_dict()) -> file:filename_all().
163168
global_cache_dir(Opts) ->
164-
Home = home_dir(),
165-
rebar_opts:get(Opts, global_rebar_dir, filename:join([Home, ".cache", "rebar3"])).
169+
rebar_opts:get(Opts, global_rebar_dir, basedir(user_cache)).
166170

167171
%% @doc appends the cache directory to the path passed to this function.
168172
-spec local_cache_dir(file:filename_all()) -> file:filename_all().

0 commit comments

Comments
 (0)