Skip to content

Commit

Permalink
fix(emqx_management): ensure trace file dir is deleted on zip exception
Browse files Browse the repository at this point in the history
  • Loading branch information
olcai committed Jan 18, 2023
1 parent 2cf2970 commit 4218227
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions apps/emqx_management/src/emqx_mgmt_api_trace.erl
Expand Up @@ -471,10 +471,15 @@ download_trace_log(get, #{bindings := #{name := Name}, query_string := Query}) -
%% Write files to ZipDir and create an in-memory zip file
Zips = group_trace_file(ZipDir, TraceLog, TraceFiles),
ZipName = binary_to_list(Name) ++ ".zip",
{ok, {ZipName, Binary}} = zip:zip(ZipName, Zips, [memory, {cwd, ZipDir}]),
%% emqx_trace:delete_files_after_send(ZipFileName, Zips),
%% TODO use file replace file_binary.(delete file after send is not ready now).
ok = file:del_dir_r(ZipDir),
Binary =
try
{ok, {ZipName, Bin}} = zip:zip(ZipName, Zips, [memory, {cwd, ZipDir}]),
Bin
after
%% emqx_trace:delete_files_after_send(ZipFileName, Zips),
%% TODO use file replace file_binary.(delete file after send is not ready now).
ok = file:del_dir_r(ZipDir)
end,
?tp(trace_api_download_trace_log, #{
files => Zips,
name => Name,
Expand Down

0 comments on commit 4218227

Please sign in to comment.