Skip to content

Commit dd43bf6

Browse files
committed
Merge pull request #961 from basho/feature/add-cleanup-intercepts
Add cleanup intercepts fuction
2 parents 0816c31 + 6157fe2 commit dd43bf6

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

intercepts/intercept.erl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
%% Export explicit API but also send compile directive to export all
2323
%% because some of these private functions are useful in their own
2424
%% right.
25-
-export([add/3, add/4]).
25+
-export([add/3, add/4, clean/1]).
2626
-compile(export_all).
2727

2828
-type abstract_code() :: term().
@@ -54,7 +54,7 @@
5454
%% functions.
5555
%%
5656
%% E.g. `[{{update_perform,2}, sleep_update_perform}]'
57-
-spec add(module(), module(), mapping()) -> ok.
57+
-spec add(module(), module(), mapping(), string()) -> ok.
5858
add(Target, Intercept, Mapping, OutDir) ->
5959
Original = ?ORIGINAL(Target),
6060
TargetAC = get_abstract_code(Target),
@@ -66,9 +66,22 @@ add(Target, Intercept, Mapping, OutDir) ->
6666
ok = compile_and_load(Original, OrigAC, OutDir),
6767
ok = compile_and_load(Target, ProxyAC, OutDir).
6868

69+
-spec add(module(), module(), mapping()) -> ok.
6970
add(Target, Intercept, Mapping) ->
7071
add(Target, Intercept, Mapping, undefined).
7172

73+
%% @doc Cleanup proxy and backuped original module
74+
-spec clean(module()) -> ok|{error, term()}.
75+
clean(Target) ->
76+
_ = code:purge(Target),
77+
_ = code:purge(?ORIGINAL(Target)),
78+
case code:load_file(Target) of
79+
{module, Target} ->
80+
ok;
81+
{error, Reason} ->
82+
{error, Reason}
83+
end.
84+
7285
%% @private
7386
%%
7487
%% @doc Compile the abstract code `AC' and load it into the code server.

src/rt_intercept.erl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ add(Node, {Target, Intercept, Mapping}, OutDir) ->
7878
NMapping = [transform_anon_fun(M) || M <- Mapping],
7979
ok = rpc:call(Node, intercept, add, [Target, Intercept, NMapping, OutDir]).
8080

81+
clean(Node, Targets) when is_list(Targets) ->
82+
[ok = clean(Node, T) || T <- Targets],
83+
ok;
84+
clean(Node, Target) ->
85+
ok = rpc:call(Node, intercept, clean, [Target]).
86+
8187
%% The following function transforms anonymous function mappings passed
8288
%% from an Erlang shell. Anonymous intercept functions from compiled code
8389
%% require the developer to supply free variables themselves, and also

0 commit comments

Comments
 (0)