Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

60 lignes
1.8 KiB

  1. %% Vendored from hex_core v0.5.1, do not edit manually
  2. % @private
  3. % Excerpt from https://github.com/erlang/otp/blob/OTP-20.0.1/lib/stdlib/src/filename.erl#L761-L788
  4. % with modifications for changing local function calls to remote function calls
  5. % to the `filename` module, for the functions `pathtype/1`, `split/1`, and `join/1`
  6. %
  7. % safe_relative_path/1 was not present in earlier OTP releases.
  8. %%
  9. %% %CopyrightBegin%
  10. %%
  11. %% Copyright Ericsson AB 1997-2017. All Rights Reserved.
  12. %%
  13. %% Licensed under the Apache License, Version 2.0 (the "License");
  14. %% you may not use this file except in compliance with the License.
  15. %% You may obtain a copy of the License at
  16. %%
  17. %% http://www.apache.org/licenses/LICENSE-2.0
  18. %%
  19. %% Unless required by applicable law or agreed to in writing, software
  20. %% distributed under the License is distributed on an "AS IS" BASIS,
  21. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. %% See the License for the specific language governing permissions and
  23. %% limitations under the License.
  24. %%
  25. %% %CopyrightEnd%
  26. %%
  27. -module(r3_hex_filename).
  28. -export([safe_relative_path/1]).
  29. safe_relative_path(Path) ->
  30. case filename:pathtype(Path) of
  31. relative ->
  32. Cs0 = filename:split(Path),
  33. safe_relative_path_1(Cs0, []);
  34. _ ->
  35. unsafe
  36. end.
  37. safe_relative_path_1(["."|T], Acc) ->
  38. safe_relative_path_1(T, Acc);
  39. safe_relative_path_1([<<".">>|T], Acc) ->
  40. safe_relative_path_1(T, Acc);
  41. safe_relative_path_1([".."|T], Acc) ->
  42. climb(T, Acc);
  43. safe_relative_path_1([<<"..">>|T], Acc) ->
  44. climb(T, Acc);
  45. safe_relative_path_1([H|T], Acc) ->
  46. safe_relative_path_1(T, [H|Acc]);
  47. safe_relative_path_1([], []) ->
  48. [];
  49. safe_relative_path_1([], Acc) ->
  50. filename:join(lists:reverse(Acc)).
  51. climb(_, []) ->
  52. unsafe;
  53. climb(T, [_|Acc]) ->
  54. safe_relative_path_1(T, Acc).