From 5cf7483f4688c9f870ccd8f8892507f3e1e3825d Mon Sep 17 00:00:00 2001 From: Jakub Czarniecki Date: Fri, 10 Mar 2017 15:50:39 +0000 Subject: [PATCH 1/2] Fix recursive directory listing in jesse database --- src/jesse_database.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jesse_database.erl b/src/jesse_database.erl index a8ec5c2..c19fe0c 100644 --- a/src/jesse_database.erl +++ b/src/jesse_database.erl @@ -233,7 +233,7 @@ list_dir(Path0) -> Path = filename:join([Path0, Filename]), case filelib:is_dir(Path) of true -> - [list_dir(Path) | Acc]; + list_dir(Path) ++ Acc; false -> [Path | Acc] end From 3b874ef0ef4092ff42f1d287dd027ab482e4c6e5 Mon Sep 17 00:00:00 2001 From: Jakub Czarniecki Date: Fri, 10 Mar 2017 17:22:36 +0000 Subject: [PATCH 2/2] Replace custom directory listing with filelib:fold_files/5 --- src/jesse_database.erl | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/jesse_database.erl b/src/jesse_database.erl index c19fe0c..25e779b 100644 --- a/src/jesse_database.erl +++ b/src/jesse_database.erl @@ -224,23 +224,15 @@ list_outdated(Path) -> lists:filter(fun is_outdated/1, Files) end. +%% @doc Recursively lists all regular files from a directory `Dir`. %% @private -list_dir(Path0) -> - {ok, Listing} = file:list_dir(Path0), - lists:foldl( fun([], Acc) -> - Acc; - (Filename, Acc) -> - Path = filename:join([Path0, Filename]), - case filelib:is_dir(Path) of - true -> - list_dir(Path) ++ Acc; - false -> - [Path | Acc] - end - end - , [] - , Listing - ). +list_dir(Dir) -> + filelib:fold_files( Dir + , "^.*$" %% Allow any regular file. + , true + , fun(Path, Acc) -> [Path | Acc] end + , [] + ). %% @doc Checks if a schema file `Filename' has an outdated cache entry. %% @private