summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-12-19 08:15:29 -0500
committerFred Hebert <mononcqc@ferd.ca>2015-12-19 08:15:29 -0500
commitbc98358643dac7dd4c92fcfa340ed9ccb41168cd (patch)
treebaca0b2837740bacd3a38c3178655290dcf47989
parentc66bce829cdf3d11d3640acf8c8be3732ac6e2c6 (diff)
parentd0180cc94d92a8580db9235a7697e93f94c5ff02 (diff)
Merge branch 'master' of https://github.com/schutm/rebar3 into schutm-wrong-paths
-rw-r--r--src/rebar_dir.erl31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl
index 09e3114..3729704 100644
--- a/src/rebar_dir.erl
+++ b/src/rebar_dir.erl
@@ -121,8 +121,37 @@ processing_base_dir(State, Dir) ->
AbsDir = filename:absname(Dir),
AbsDir =:= rebar_state:get(State, base_dir).
+make_absolute_path(Path) ->
+ case filename:pathtype(Path) of
+ absolute ->
+ Path;
+ relative ->
+ {ok, Dir} = file:get_cwd(),
+ filename:join([Dir, Path]);
+ volumerelative ->
+ Volume = hd(filename:split(Path)),
+ {ok, Dir} = file:get_cwd(Volume),
+ filename:join([Dir, Path])
+ end.
+
+make_normalized_path(Path) ->
+ AbsPath = make_absolute_path(Path),
+ Components = filename:split(AbsPath),
+ make_normalized_path(Components, []).
+
+make_normalized_path([], NormalizedPath) ->
+ filename:join(lists:reverse(NormalizedPath));
+make_normalized_path([H|T], NormalizedPath) ->
+ case H of
+ "." -> make_normalized_path(T, NormalizedPath);
+ ".." -> make_normalized_path(T, tl(NormalizedPath));
+ _ -> make_normalized_path(T, [H|NormalizedPath])
+ end.
+
make_relative_path(Source, Target) ->
- do_make_relative_path(filename:split(Source), filename:split(Target)).
+ AbsSource = make_normalized_path(Source),
+ AbsTarget = make_normalized_path(Target),
+ do_make_relative_path(filename:split(AbsSource), filename:split(AbsTarget)).
do_make_relative_path([H|T1], [H|T2]) ->
do_make_relative_path(T1, T2);