@@ -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- % % Overwrites the current table if it exists .
309+ % % Overwrites the current table if it is empty .
310310-spec load (file :name_all ()) -> {ok , table ()} | {error , any ()}.
311311load (File ) when is_binary (File ) ->
312312 load (binary_to_list (File ));
@@ -566,15 +566,18 @@ handle_call({dump, File}, _From, State = #{tab := Tab}) ->
566566 Reply = ets :tab2file (Tab , File ),
567567 {reply , Reply , State };
568568handle_call ({load , File }, _From , State ) ->
569- case ets :info (maps :get (tab , State ), id ) of
570- undefined ->
571- ok ;
569+ Tab = maps :get (tab , State ),
570+ Reply = case {ets :info (Tab , id ), ets :info (Tab , size )} of
571+ {undefined , _ } ->
572+ ets :file2tab (File );
573+ {_ , 0 } ->
574+ ets :delete (Tab ),
575+ ets :file2tab (File );
572576 _ ->
573- ets : delete ( maps : get ( tab , State ))
577+ { error , { non_empty_trace_table , Tab }}
574578 end ,
575- Reply = ets :file2tab (File ),
576579 NewState = case Reply of
577- {ok , Tab } -> State #{tab := Tab , index := index (Tab )};
580+ {ok , NewTab } -> State #{tab := NewTab , index := index (NewTab )};
578581 _ -> State
579582 end ,
580583 {reply , Reply , NewState };
0 commit comments