From 01a1ce8f050acf9def738e86ef69641d10e4a250 Mon Sep 17 00:00:00 2001 From: Pablo Costas Date: Fri, 7 Aug 2020 17:06:13 +0200 Subject: [PATCH] Add extra pattern matching clause to not crash handling with keep_logs --- src/rebar_prv_common_test.erl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 91913ac69..c27c1bfbc 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -699,13 +699,16 @@ handle_keep_logs(LogDir, N) -> case Dirs of %% first time running the tests, there are no logs to delete [] -> ok; - _ -> + %% during the next run we would crash because of keep_logs + _ when length(Dirs) >= N -> 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 + ok; + %% we still dont have enough log run directories as to crash + _ -> ok end; _ -> ok end.