Skip to content

Commit

Permalink
Display warnings when cache dirs are read-only
Browse files Browse the repository at this point in the history
This should provide more help to users directly and avoid having them go
through opening tickets for help.

Fixes #1767
  • Loading branch information
ferd committed Apr 27, 2018
1 parent 7eca596 commit df9c769
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/rebar_packages.erl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ registry_dir(State) ->
case rebar_state:get(State, rebar_packages_cdn, ?DEFAULT_CDN) of
?DEFAULT_CDN ->
RegistryDir = filename:join([CacheDir, "hex", "default"]),
ok = filelib:ensure_dir(filename:join(RegistryDir, "placeholder")),
case filelib:ensure_dir(filename:join(RegistryDir, "placeholder")) of
ok -> ok;
{error, Posix} when Posix == eaccess; Posix == enoent ->
?ABORT("Could not write to ~p. Please ensure the path is writeable.",
[RegistryDir])
end,
{ok, RegistryDir};
CDN ->
case rebar_utils:url_append_path(CDN, ?REMOTE_PACKAGE_DIR) of
Expand Down
11 changes: 10 additions & 1 deletion src/rebar_prv_local_install.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
-export([extract_escript/2]).

-include("rebar.hrl").
-include_lib("providers/include/providers.hrl").
-include_lib("kernel/include/file.hrl").

-define(PROVIDER, install).
Expand Down Expand Up @@ -54,6 +55,9 @@ do(State) ->
end.

-spec format_error(any()) -> iolist().
format_error({non_writeable, Dir}) ->
io_lib:format("Could not write to ~p. Please ensure the path is writeable.",
[Dir]);
format_error(Reason) ->
io_lib:format("~p", [Reason]).

Expand All @@ -71,7 +75,12 @@ extract_escript(State, ScriptPath) ->
%% And add a rebar3 bin script to ~/.cache/rebar3/bin
Opts = rebar_state:opts(State),
OutputDir = filename:join(rebar_dir:global_cache_dir(Opts), "lib"),
filelib:ensure_dir(filename:join(OutputDir, "empty")),
case filelib:ensure_dir(filename:join(OutputDir, "empty")) of
ok ->
ok;
{error, Posix} when Posix == eaccess; Posix == enoent ->
throw(?PRV_ERROR({non_writeable, OutputDir}))
end,

?INFO("Extracting rebar3 libs to ~ts...", [OutputDir]),
zip:extract(Archive, [{cwd, OutputDir}]),
Expand Down

0 comments on commit df9c769

Please sign in to comment.