Skip to content

Commit 34eb8d6

Browse files
committed
Make load() work after a clean start
At the cost of making it drop the current table. However, it shouldn't be a big deal ergonomics-wise, since `load()` is most often used when the current table is empty in order to populate it.
1 parent 4b883f7 commit 34eb8d6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/tr.erl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ set_tab(Tab) when is_atom(Tab) ->
306306

307307
%% @doc Loads an ETS trace table from a file, and makes it the current table.
308308
%%
309-
%% Fails if the table already exists.
309+
%% Overwrites the current table if it exists.
310310
-spec load(file:name_all()) -> {ok, table()} | {error, any()}.
311311
load(File) when is_binary(File) ->
312312
load(binary_to_list(File));
@@ -566,6 +566,12 @@ handle_call({dump, File}, _From, State = #{tab := Tab}) ->
566566
Reply = ets:tab2file(Tab, File),
567567
{reply, Reply, State};
568568
handle_call({load, File}, _From, State) ->
569+
case ets:info(maps:get(tab, State), id) of
570+
undefined ->
571+
ok;
572+
_ ->
573+
ets:delete(maps:get(tab, State))
574+
end,
569575
Reply = ets:file2tab(File),
570576
NewState = case Reply of
571577
{ok, Tab} -> State#{tab := Tab, index := index(Tab)};

0 commit comments

Comments
 (0)