瀏覽代碼

Merge pull request #2320 from pablocostass/fix_keep_logs_crash

Fix keep_logs option crashing when having more than N directories
pull/2321/head
Fred Hebert 4 年之前
committed by GitHub
父節點
當前提交
c17b7b01cc
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: 4AEE18F83AFDEB23
共有 2 個檔案被更改,包括 29 行新增0 行删除
  1. +3
    -0
      rebar.config
  2. +26
    -0
      src/rebar_prv_common_test.erl

+ 3
- 0
rebar.config 查看文件

@ -49,6 +49,9 @@
{exclude_mods, [rebar_prv_alias]}
]}.
%% Keep only the logs of the last 5 runs
{ct_opts, [{keep_logs, 5}]}.
%% Profiles
{profiles, [{test, [
{deps, [{meck, "0.8.13"}]},

+ 26
- 0
src/rebar_prv_common_test.erl 查看文件

@ -686,12 +686,38 @@ translate(State, [], Path) ->
{error, badparent} -> Path
end.
-spec handle_keep_logs(file:filename(), pos_integer()) -> ok.
handle_keep_logs(LogDir, N) ->
case file:list_dir(LogDir) of
{ok, Filenames} ->
Dirs = lists:filter(fun(File) ->
filelib:is_dir(filename:join([LogDir, File]))
end, Filenames) -- ["last"], %% we ignore the symlink as we later handle it
case Dirs of
%% first time running the tests, there are no logs to delete
[] -> ok;
_ ->
SortedDirs = lists:reverse(lists:sort(Dirs)),
%% sort the log dirs and keep the N - 1 newest
{_Keep, Discard} = lists:split(N - 1, SortedDirs),
?DEBUG("Removing the following directories because keep_logs option was found: ~p", [Discard]),
[rebar_file_utils:rm_rf(filename:join([LogDir, Dir])) || Dir <- Discard],
ok
end;
_ -> ok
end.
setup_logdir(State, Opts) ->
Logdir = case proplists:get_value(logdir, Opts) of
undefined -> filename:join([rebar_dir:base_dir(State), "logs"]);
Dir -> Dir
end,
filelib:ensure_dir(filename:join([Logdir, "dummy.beam"])),
case proplists:get_value(keep_logs, Opts) of
all -> ok;
undefined -> ok;
N -> handle_keep_logs(Logdir, N)
end,
[{logdir, Logdir}|lists:keydelete(logdir, 1, Opts)].
turn_off_auto_compile(Opts) ->

Loading…
取消
儲存