diff options
author | Tristan Sloughter <t@crashfast.com> | 2015-12-19 10:18:55 -0600 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2015-12-19 10:18:55 -0600 |
commit | ddc64cd66b2d6e4e2315ee281b9eabb8bc2e8868 (patch) | |
tree | edfdfc09336275df1953deea682bfb7c4cbf3b9b /src | |
parent | 362d5c81e74c53727e7509b95e04eb4db7d039ac (diff) | |
parent | 9e01db6852a45cebfe4d59e418750b0782b43516 (diff) |
Merge pull request #988 from ferd/schutm-wrong-paths
Fix wrong relative path resolution
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_dir.erl | 31 |
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); |