summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-09-27 19:01:44 -0400
committerFred Hebert <mononcqc@ferd.ca>2017-09-27 19:21:37 -0400
commitcf83eb7fc45fac677a83b5f38e87c581cf516cf2 (patch)
treea01cef1a8c93e6a1c5d72d89a8f5ac6a82bbc0cb
parentc3f01c60139977dfad4723748e7c2f493fffd0ae (diff)
Corrects a fix to src_dir values
The previous patch at #7c959cc fixed the usage of duplicate values for directories through relative paths, but mistakenly went overboard and dropped the `./` path, which is still fairly common. Similarly for `../". The code is modified to special-case such values and keep the code working.
-rw-r--r--src/rebar_dir.erl4
-rw-r--r--test/rebar_dir_SUITE.erl5
2 files changed, 6 insertions, 3 deletions
diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl
index 7a779d1..7182c10 100644
--- a/src/rebar_dir.erl
+++ b/src/rebar_dir.erl
@@ -197,8 +197,10 @@ make_normalized_path([], NormalizedPath) ->
filename:join(lists:reverse(NormalizedPath));
make_normalized_path([H|T], NormalizedPath) ->
case H of
+ "." when NormalizedPath == [], T == [] -> make_normalized_path(T, ["."]);
"." -> make_normalized_path(T, NormalizedPath);
- ".." -> make_normalized_path(T, tl(NormalizedPath));
+ ".." when NormalizedPath == [] -> make_normalized_path(T, [".."]);
+ ".." when hd(NormalizedPath) =/= ".." -> make_normalized_path(T, tl(NormalizedPath));
_ -> make_normalized_path(T, [H|NormalizedPath])
end.
diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl
index 3b8e1fc..4743865 100644
--- a/test/rebar_dir_SUITE.erl
+++ b/test/rebar_dir_SUITE.erl
@@ -68,10 +68,11 @@ default_all_src_dirs(Config) ->
["src", "test"] = rebar_dir:all_src_dirs(rebar_state:opts(State), ["src"], ["test"]).
src_dirs(Config) ->
- RebarConfig = [{erl_opts, [{src_dirs, ["foo", "./bar", "bar", "bar/", "./bar/", "baz"]}]}],
+ RebarConfig = [{erl_opts, [{src_dirs, ["foo", "./bar", "bar", "bar/", "./bar/", "baz",
+ "./", ".", "../", "..", "./../", "../.", ".././../"]}]}],
{ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
- ["bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State)).
+ [".", "..", "../..", "bar", "baz", "foo"] = rebar_dir:src_dirs(rebar_state:opts(State)).
src_dirs_with_opts(Config) ->
RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]},