Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

76 рядки
2.5 KiB

15 роки тому
15 роки тому
15 роки тому
15 роки тому
15 роки тому
15 роки тому
  1. %% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
  2. %% ex: ts=4 sw=4 et
  3. %% -------------------------------------------------------------------
  4. %%
  5. %% rebar: Erlang Build Tools
  6. %%
  7. %% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com)
  8. %%
  9. %% Permission is hereby granted, free of charge, to any person obtaining a copy
  10. %% of this software and associated documentation files (the "Software"), to deal
  11. %% in the Software without restriction, including without limitation the rights
  12. %% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. %% copies of the Software, and to permit persons to whom the Software is
  14. %% furnished to do so, subject to the following conditions:
  15. %%
  16. %% The above copyright notice and this permission notice shall be included in
  17. %% all copies or substantial portions of the Software.
  18. %%
  19. %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. %% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. %% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. %% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. %% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. %% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. %% THE SOFTWARE.
  26. %% -------------------------------------------------------------------
  27. -module(rebar_file_utils).
  28. -export([rm_rf/1,
  29. mkdir_p/1,
  30. cp_r/2,
  31. ln_sf/2,
  32. delete_each/1]).
  33. -include("rebar.hrl").
  34. %% ===================================================================
  35. %% Public API
  36. %% ===================================================================
  37. rm_rf(Target) ->
  38. [] = os:cmd(?FMT("rm -rf ~s", [Target])),
  39. ok.
  40. mkdir_p(Target) ->
  41. [] = os:cmd(?FMT("mkdir -p ~s", [Target])),
  42. ok.
  43. cp_r(Sources, Dest) ->
  44. SourceStr = string:join(Sources, " "),
  45. [] = os:cmd(?FMT("cp -R ~s ~s", [SourceStr, Dest])),
  46. ok.
  47. ln_sf(Source, Dest) ->
  48. case filelib:is_dir(Dest) of
  49. true ->
  50. ActualDest = filename:join([Dest, filename:basename(Source)]);
  51. false ->
  52. ActualDest = Dest
  53. end,
  54. [] = os:cmd(?FMT("ln -sf ~s ~s", [Source, ActualDest])),
  55. ok.
  56. delete_each([]) ->
  57. ok;
  58. delete_each([File | Rest]) ->
  59. case file:delete(File) of
  60. ok ->
  61. delete_each(Rest);
  62. {error, enoent} ->
  63. delete_each(Rest);
  64. {error, Reason} ->
  65. ?ERROR("Failed to delete file ~s: ~p\n", [File, Reason]),
  66. ?FAIL
  67. end.