Skip to content

Commit

Permalink
Potentially create global cache dir (rebar3) if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ferraz-oliveira committed Aug 8, 2023
1 parent a18dee5 commit c48dac8
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/rebar3_checkshell_inst.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
-spec put_executables() -> Result when
Result :: ok | {error, nonempty_ubytes()}.
put_executables() ->
GlobalCacheDirExists = filelib:is_dir(global_cache_dir()),
GlobalCacheDirResult = mkdir_global_cache(GlobalCacheDirExists),

ArchCacheDirExists = filelib:is_dir(arch_cache_dir()),
CacheDirResult = mkdir_arch_cache(ArchCacheDirExists),
CacheDirResult = mkdir_arch_cache(ArchCacheDirExists, GlobalCacheDirResult),

VsnCacheDirExists = filelib:is_dir(vsn_cache_dir()),
VsnDirResult = mkdir_vsn_cache(VsnCacheDirExists, CacheDirResult),
Expand Down Expand Up @@ -105,13 +108,29 @@ executable_for(linux) ->
executable_for(win32) ->
"shellcheck.exe".

-spec mkdir_arch_cache(Exists) -> Result when
-spec mkdir_global_cache(Exists) -> Result when
Exists :: boolean(),
Result :: ok | {error, file:posix()}.
mkdir_global_cache(true = _Exists) ->
ok;
mkdir_global_cache(false = _Exists) ->
GlobalCacheDir = global_cache_dir(),
_ = rebar_log:log(warn, "checkshell: creating global cache dir at ~p. Is this a CI env.?", [
GlobalCacheDir
]),
filelib:ensure_path(GlobalCacheDir).

-spec mkdir_arch_cache(Exists, GlobalCacheDirResult) -> Result when
Exists :: boolean(),
GlobalCacheDirResult :: ok | {error, file:posix()},
Result :: ok | {error, file:posix()}.
mkdir_arch_cache(true = _Exists) ->
mkdir_arch_cache(true = _Exists, _GlobalCacheDirResult) ->
_ = rebar_log:log(debug, "checkshell: arch. cache dir exists", []),
ok;
mkdir_arch_cache(false = _Exists) ->
mkdir_arch_cache(false = _Exists, {error, _FilePosix} = GlobalCacheDirResult) ->
_ = rebar_log:log(debug, "checkshell: (arch. cache) prior error ~p", [GlobalCacheDirResult]),
GlobalCacheDirResult;
mkdir_arch_cache(false = _Exists, ok = _GlobalCacheDirResult) ->
ArchFolderName = arch_folder_name(),
ArchCacheDir = arch_cache_dir(),
_ = rebar_log:log(info, "checkshell: creating cache/arch. dir (arch: ~p) at ~p", [
Expand Down

0 comments on commit c48dac8

Please sign in to comment.