diff options
author | alisdair sullivan <alisdair.sullivan@askuity.com> | 2015-09-14 11:46:53 -0700 |
---|---|---|
committer | alisdair sullivan <alisdair.sullivan@askuity.com> | 2015-09-14 11:46:53 -0700 |
commit | ae275c6396545defc80a765a6b835d01f4c76599 (patch) | |
tree | a58ef845596c5310cc2c0f1bb08b7032c06493c7 /src | |
parent | 6a8948544838073d5c5f829403ee7e7f1d6cf4d9 (diff) |
function name changes:
`reduce_path/1` -> `canonical_path/1`
`relative_path/2` -> `path_from_ancestor/2`
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_dir.erl | 12 | ||||
-rw-r--r-- | src/rebar_file_utils.erl | 36 |
2 files changed, 24 insertions, 24 deletions
diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index bbc7394..364e197 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -175,15 +175,15 @@ retarget_path(State, Path) -> %% not relative to any apps in project, check to see it's relative to %% project root retarget_path(State, Path, []) -> - case rebar_file_utils:relative_path(rebar_file_utils:reduce_path(Path), rebar_state:dir(State)) of - {ok, NewPath} -> filename:join([base_dir(State), NewPath]); + case rebar_file_utils:path_from_ancestor(rebar_file_utils:canonical_path(Path), rebar_state:dir(State)) of + {ok, NewPath} -> filename:join([base_dir(State), NewPath]); %% not relative to project root, don't modify - {error, not_relative} -> Path + {error, badparent} -> Path end; %% relative to current app, retarget to the same dir relative to %% the app's out_dir retarget_path(State, Path, [App|Rest]) -> - case rebar_file_utils:relative_path(rebar_file_utils:reduce_path(Path), rebar_app_info:dir(App)) of - {ok, NewPath} -> filename:join([rebar_app_info:out_dir(App), NewPath]); - {error, not_relative} -> retarget_path(State, Path, Rest) + case rebar_file_utils:path_from_ancestor(rebar_file_utils:canonical_path(Path), rebar_app_info:dir(App)) of + {ok, NewPath} -> filename:join([rebar_app_info:out_dir(App), NewPath]); + {error, badparent} -> retarget_path(State, Path, Rest) end. diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index 26d4da0..ea1a6a2 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -38,8 +38,8 @@ system_tmpdir/1, reset_dir/1, touch/1, - relative_path/2, - reduce_path/1]). + path_from_ancestor/2, + canonical_path/1]). -include("rebar.hrl"). @@ -247,29 +247,29 @@ touch(Path) -> atime = calendar:local_time()}). %% for a given path return the path relative to a base directory --spec relative_path(string(), string()) -> {ok, string()} | {error, not_relative}. +-spec path_from_ancestor(string(), string()) -> {ok, string()} | {error, badparent}. -relative_path(Target, To) -> - relative_path1(filename:split(reduce_path(Target)), - filename:split(reduce_path(To))). +path_from_ancestor(Target, To) -> + path_from_ancestor_(filename:split(canonical_path(Target)), + filename:split(canonical_path(To))). -relative_path1([Part|Target], [Part|To]) -> relative_path1(Target, To); -relative_path1([], []) -> {ok, ""}; -relative_path1(Target, []) -> {ok, filename:join(Target)}; -relative_path1(_, _) -> {error, not_relative}. +path_from_ancestor_([Part|Target], [Part|To]) -> path_from_ancestor_(Target, To); +path_from_ancestor_([], []) -> {ok, ""}; +path_from_ancestor_(Target, []) -> {ok, filename:join(Target)}; +path_from_ancestor_(_, _) -> {error, badparent}. %% reduce a filepath by removing all incidences of `.' and `..' --spec reduce_path(string()) -> string(). +-spec canonical_path(string()) -> string(). -reduce_path(Dir) -> reduce_path([], filename:split(filename:absname(Dir))). +canonical_path(Dir) -> canonical_path([], filename:split(filename:absname(Dir))). -reduce_path([], []) -> filename:nativename("/"); -reduce_path(Acc, []) -> filename:join(lists:reverse(Acc)); -reduce_path(Acc, ["."|Rest]) -> reduce_path(Acc, Rest); -reduce_path([_|Acc], [".."|Rest]) -> reduce_path(Acc, Rest); -reduce_path([], [".."|Rest]) -> reduce_path([], Rest); -reduce_path(Acc, [Component|Rest]) -> reduce_path([Component|Acc], Rest). +canonical_path([], []) -> filename:nativename("/"); +canonical_path(Acc, []) -> filename:join(lists:reverse(Acc)); +canonical_path(Acc, ["."|Rest]) -> canonical_path(Acc, Rest); +canonical_path([_|Acc], [".."|Rest]) -> canonical_path(Acc, Rest); +canonical_path([], [".."|Rest]) -> canonical_path([], Rest); +canonical_path(Acc, [Component|Rest]) -> canonical_path([Component|Acc], Rest). %% =================================================================== %% Internal functions |