From c555854d97239080ce75cbc7a7cf58ffe7ac4489 Mon Sep 17 00:00:00 2001 From: liyuxi Date: Tue, 7 Mar 2023 10:17:22 +0000 Subject: [PATCH] fix download log file --- plugins/restful/log_handle.c | 58 ++++++++++-------------------------- 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/plugins/restful/log_handle.c b/plugins/restful/log_handle.c index 3b0530ed..f9220d11 100644 --- a/plugins/restful/log_handle.c +++ b/plugins/restful/log_handle.c @@ -54,43 +54,27 @@ void handle_logs_files(nng_aio *aio) NEU_VALIDATE_JWT(aio); - rv = mkdir("neuron_logs", S_IRWXU); - if (0 != rv && EEXIST == errno) { - rv = 0; - } - - // check if coredump exists - rv = access("./core", F_OK); - if (0 == rv) { - rv = system("cp -r ./core neuron_logs"); - if (0 != rv) { - nlog_error("failed to copy coredump file"); - NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, { - neu_http_response(aio, error_code.error, result_error); - }); - return; - } - } - - rv = system("cp -r ./logs neuron_logs"); + /* check whether the neuron directory exists */ + rv = access("../neuron", F_OK); if (0 != rv) { - nlog_error("failed to copy logs file"); + nlog_error("The neuron directory does not exists"); + NEU_JSON_RESPONSE_ERROR(NEU_ERR_FILE_NOT_EXIST, { + neu_http_response(aio, error_code.error, result_error); + }); + return; + } + + /* tar the neuron directory */ + rv = system("tar -zcvf neuron_debug.tar.gz ../neuron"); + if (0 != rv) { + nlog_error("failed to create neuron_debug.tar.gz"); NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, { neu_http_response(aio, error_code.error, result_error); }); return; } - rv = system("tar -zcvf neuron_logs.tar.gz neuron_logs"); - if (0 != rv) { - nlog_error("failed to create neuron_logs.tar.gz"); - NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, { - neu_http_response(aio, error_code.error, result_error); - }); - return; - } - - strcpy(path, "neuron_logs.tar.gz"); + strcpy(path, "neuron_debug.tar.gz"); rv = read_file(path, &data, &len); if (0 != rv) { NEU_JSON_RESPONSE_ERROR( @@ -98,18 +82,8 @@ void handle_logs_files(nng_aio *aio) return; } - // delete neuron_logs folder from build - rv = system("rm -rf neuron_logs.tar.gz neuron_logs"); - if (0 != rv) { - nlog_error("failed to delete neuron_logs folder"); - NEU_JSON_RESPONSE_ERROR(NEU_ERR_COMMAND_EXECUTION_FAILED, { - neu_http_response(aio, error_code.error, result_error); - }); - return; - } - - // handle http response - strcpy(disp, "attachment; filename=neuron_logs.tar.gz"); + /* handle http response */ + strcpy(disp, "attachment; filename=neuron_debug.tar.gz"); rv = neu_http_response_file(aio, data, len, disp); if (0 != rv) { return;