fix(trace): download trace request not compelete but the zip file is delete sometimes
This commit is contained in:
parent
87bff075ad
commit
d0e8285e93
|
@ -304,13 +304,16 @@ download_trace_log(get, #{bindings := #{name := Name}}) ->
|
||||||
Zips = group_trace_file(ZipDir, TraceLog, TraceFiles),
|
Zips = group_trace_file(ZipDir, TraceLog, TraceFiles),
|
||||||
ZipFileName = ZipDir ++ binary_to_list(Name) ++ ".zip",
|
ZipFileName = ZipDir ++ binary_to_list(Name) ++ ".zip",
|
||||||
{ok, ZipFile} = zip:zip(ZipFileName, Zips, [{cwd, ZipDir}]),
|
{ok, ZipFile} = zip:zip(ZipFileName, Zips, [{cwd, ZipDir}]),
|
||||||
emqx_trace:delete_files_after_send(ZipFileName, Zips),
|
%% emqx_trace:delete_files_after_send(ZipFileName, Zips),
|
||||||
|
%% TODO use file replace file_binary.(delete file after send is not ready now).
|
||||||
|
{ok, Binary} = file:read_file(ZipFile),
|
||||||
|
ZipName = filename:basename(ZipFile),
|
||||||
|
file:delete(ZipFile),
|
||||||
Headers = #{
|
Headers = #{
|
||||||
<<"content-type">> => <<"application/x-zip">>,
|
<<"content-type">> => <<"application/x-zip">>,
|
||||||
<<"content-disposition">> =>
|
<<"content-disposition">> => iolist_to_binary("attachment; filename=" ++ ZipName)
|
||||||
iolist_to_binary("attachment; filename=" ++ filename:basename(ZipFile))
|
|
||||||
},
|
},
|
||||||
{200, Headers, {file, ZipFile}};
|
{200, Headers, {file_binary, ZipName, Binary}};
|
||||||
{error, not_found} -> ?NOT_FOUND(Name)
|
{error, not_found} -> ?NOT_FOUND(Name)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue