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.

50 lines
1.3 KiB

  1. %% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
  2. %% ex: ts=4 sw=4 et
  3. %%
  4. %% @doc A localfs custom resource (for testing purposes only)
  5. %%
  6. %% ```
  7. %% {deps, [
  8. %% %% Application files are copied from "/path/to/app_name"
  9. %% {app_name, {localfs, "/path/to/app_name", undefined}}
  10. %% ]}.
  11. %% '''
  12. -module(rebar_localfs_resource_v2).
  13. -behaviour(rebar_resource_v2).
  14. -export([init/2
  15. ,lock/2
  16. ,download/4
  17. ,needs_update/2
  18. ,make_vsn/2]).
  19. -include_lib("eunit/include/eunit.hrl").
  20. -spec init(atom(), rebar_state:t()) -> {ok, term()}.
  21. init(Type, _State) ->
  22. Resource = rebar_resource_v2:new(Type, ?MODULE, #{}),
  23. {ok, Resource}.
  24. lock(AppInfo, _) ->
  25. case rebar_app_info:source(AppInfo) of
  26. {localfs, Path, _Ref} ->
  27. {localfs, Path, undefined};
  28. {localfs, Path} ->
  29. {localfs, Path, undefined}
  30. end.
  31. needs_update(_AppInfo, _) ->
  32. false.
  33. download(TmpDir, AppInfo, State, _) ->
  34. download_(TmpDir, rebar_app_info:source(AppInfo), State).
  35. download_(TmpDir, {localfs, Path, _Ref}, State) ->
  36. download_(TmpDir, {localfs, Path}, State);
  37. download_(TmpDir, {localfs, Path}, _State) ->
  38. ok = rebar_file_utils:cp_r(filelib:wildcard(Path ++ "/*"), TmpDir),
  39. {ok, undefined}.
  40. make_vsn(_AppInfo, _) ->
  41. {plain, "undefined"}.