You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.4 KiB

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