summaryrefslogtreecommitdiff
path: root/test/rebar_localfs_resource_v2.erl
blob: 52af4d40fe41711e4af9344e097e6bbab5afe774 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 et
%%
%% @doc A localfs custom resource (for testing purposes only)
%%
%% ```
%% {deps, [
%%     %% Application files are copied from "/path/to/app_name"
%%     {app_name, {localfs, "/path/to/app_name", undefined}}
%% ]}.
%% '''
-module(rebar_localfs_resource_v2).

-behaviour(rebar_resource_v2).

-export([init/2
        ,lock/2
        ,download/4
        ,needs_update/2
        ,make_vsn/2]).

-include_lib("eunit/include/eunit.hrl").

-spec init(atom(), rebar_state:t()) -> {ok, term()}.
init(Type, _State) ->
    Resource = rebar_resource_v2:new(Type, ?MODULE, #{}),
    {ok, Resource}.

lock(AppInfo, _) ->
    case rebar_app_info:source(AppInfo) of
        {localfs, Path, _Ref} ->
            {localfs, Path, undefined};
        {localfs, Path} ->
            {localfs, Path, undefined}
    end.

needs_update(_AppInfo, _) ->
    false.

download(TmpDir, AppInfo, State, _) ->
    download_(TmpDir, rebar_app_info:source(AppInfo), State).

download_(TmpDir, {localfs, Path, _Ref}, State) ->
    download_(TmpDir, {localfs, Path}, State);
download_(TmpDir, {localfs, Path}, _State) ->
    ok = rebar_file_utils:cp_r(filelib:wildcard(Path ++ "/*"), TmpDir),
    {ok, undefined}.

make_vsn(_AppInfo, _) ->
    {plain, "undefined"}.