summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Avdey <eiri@eiri.ca>2018-01-04 12:55:42 -0400
committerGitHub <noreply@github.com>2018-01-04 12:55:42 -0400
commitf71daa20d4b5d521a59290363293dfa2b18802f0 (patch)
tree24609be75941f8812f5c136ecf9365eafc04c377
parent3c90cc3aa72090ad6db8675167a1af17ed5182f4 (diff)
parentb7911065ec52432ed5f04ad49b1e601ec34d6672 (diff)
downloadcouchdb-f71daa20d4b5d521a59290363293dfa2b18802f0.tar.gz
Merge pull request #1090 from apache/cleanup-on-setup_eunit
Cleanup data dirs in eunit_plugin before test run
-rw-r--r--rel/plugins/eunit_plugin.erl20
1 files changed, 20 insertions, 0 deletions
diff --git a/rel/plugins/eunit_plugin.erl b/rel/plugins/eunit_plugin.erl
index bbf83d2ec..1de20b394 100644
--- a/rel/plugins/eunit_plugin.erl
+++ b/rel/plugins/eunit_plugin.erl
@@ -32,8 +32,28 @@ build_eunit_config(Config0, AppFile) ->
Cwd = filename:absname(rebar_utils:get_cwd()),
DataDir = Cwd ++ "/tmp/data",
ViewIndexDir = Cwd ++ "/tmp/data",
+ TmpDataDir = Cwd ++ "/tmp/tmp_data",
+ cleanup_dirs([DataDir, TmpDataDir]),
Config1 = rebar_config:set_global(Config0, template, "setup_eunit"),
Config2 = rebar_config:set_global(Config1, prefix, Cwd),
Config3 = rebar_config:set_global(Config2, data_dir, DataDir),
Config = rebar_config:set_global(Config3, view_index_dir, ViewIndexDir),
rebar_templater:create(Config, AppFile).
+
+
+cleanup_dirs(Dirs) ->
+ lists:foreach(fun(Dir) ->
+ case filelib:is_dir(Dir) of
+ true -> del_dir(Dir);
+ false -> ok
+ end
+ end, Dirs).
+
+
+del_dir(Dir) ->
+ All = filelib:wildcard(Dir ++ "/**"),
+ {Dirs, Files} = lists:partition(fun filelib:is_dir/1, All),
+ ok = lists:foreach(fun file:delete/1, Files),
+ SortedDirs = lists:sort(fun(A, B) -> length(A) > length(B) end, Dirs),
+ ok = lists:foreach(fun file:del_dir/1, SortedDirs),
+ ok = file:del_dir(Dir).