summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuncer Ayaz <tuncer.ayaz@gmail.com>2011-06-16 17:38:48 +0200
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2011-07-06 20:31:40 +0200
commite0a86868cab4e091042568faa3da96b574917787 (patch)
tree16ed2096792f5260865595992efb54ed782bc25a
parent8263f12594c82edda1c5b80d2e9494fed925b423 (diff)
Log if sub_dirs loop is detected
-rw-r--r--src/rebar_subdirs.erl37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/rebar_subdirs.erl b/src/rebar_subdirs.erl
index b107978..261bdf8 100644
--- a/src/rebar_subdirs.erl
+++ b/src/rebar_subdirs.erl
@@ -27,6 +27,7 @@
-module(rebar_subdirs).
-include("rebar.hrl").
+-include_lib("kernel/include/file.hrl").
-export([preprocess/2]).
@@ -37,6 +38,38 @@
preprocess(Config, _) ->
%% Get the list of subdirs specified in the config (if any).
Cwd = rebar_utils:get_cwd(),
- Subdirs = [filename:join(Cwd, Dir) ||
- Dir <- rebar_config:get_local(Config, sub_dirs, [])],
+ Subdirs0 = rebar_config:get_local(Config, sub_dirs, []),
+ Check = check_loop(Cwd),
+ ok = lists:foreach(Check, Subdirs0),
+ Subdirs = [filename:join(Cwd, Dir) || Dir <- Subdirs0],
{ok, Subdirs}.
+
+%% ===================================================================
+%% Internal functions
+%% ===================================================================
+
+check_loop(Cwd) ->
+ RebarConfig = filename:join(Cwd, "rebar.config"),
+ fun(Dir0) ->
+ IsSymlink = case file:read_link_info(Dir0) of
+ {ok, #file_info{type=symlink}} ->
+ {true, resolve_symlink(Dir0)};
+ _ ->
+ {false, Dir0}
+ end,
+ case IsSymlink of
+ {false, Dir="."} ->
+ ?ERROR("endless loop detected:~nsub_dirs"
+ " entry ~p in ~s~n", [Dir, RebarConfig]);
+ {true, Cwd} ->
+ ?ERROR("endless loop detected:~nsub_dirs"
+ " entry ~p in ~s is a symlink to \".\"~n",
+ [Dir0, RebarConfig]);
+ _ ->
+ ok
+ end
+ end.
+
+resolve_symlink(Dir0) ->
+ {ok, Dir} = file:read_link(Dir0),
+ Dir.