From ee74952f94f21851506cfd25a3ad7f9318d9d378 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Sat, 8 Jun 2024 12:05:03 +0800 Subject: [PATCH] =?utf8?q?=E8=A1=A5=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../drivers/peripheral/utils/custom_utils.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index a3a32f7c8..9a683eac8 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -1577,7 +1577,7 @@ void uapi_delete_files(void) int uapi_save_exc(void) { - const char *folderPath = "/user/exc"; + const char *folderPath = "/user/exc"; const char *tarPath = "/user/tar/exc_%d.tar"; DIR *dir; @@ -1589,6 +1589,7 @@ int uapi_save_exc(void) size_t bytesRead = 0; FILE *fp; + struct stat file_inf; int ret = 0; uint32_t timestamp = get_local_timestamp(); @@ -1599,14 +1600,14 @@ int uapi_save_exc(void) ret = mtar_open(&tar, str, "w"); if (ret != MTAR_ESUCCESS) { - PRINT("Unable to open/create %s\r\n",str); + PRINT("unable to open/create %s\r\n",str); return -1; } dir = opendir(folderPath); if (dir == NULL) { - PRINT("Unable to open %s\r\n",folderPath); + PRINT("unable to open %s\r\n",folderPath); return -1; } @@ -1615,18 +1616,22 @@ int uapi_save_exc(void) if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { char filePath[64]; - snprintf(filePath, sizeof(filePath), "%s/%s", filePath, entry->d_name); + snprintf(filePath, sizeof(filePath), "%s/%s", folderPath, entry->d_name); fp = fopen(filePath, "r"); if(fp == NULL) { - PRINT("Unable to open %s\n", filePath); + PRINT("uable to open %s\r\n", filePath); return -1; } - while ((bytesRead = fread(buffer, 1, sizeof(buffer), fp) > 0) ) + memset(&file_inf, 0, sizeof(file_inf)); + stat(filePath, &file_inf); + + mtar_write_file_header(&tar, entry->d_name, file_inf.st_size); + + while((bytesRead = fread(buffer, 1, sizeof(buffer), fp)) > 0) { - mtar_write_file_header(&tar, entry->d_name, bytesRead); mtar_write_data(&tar, buffer, bytesRead); memset(buffer, 0, sizeof(buffer)); -- 2.17.1