From 7c5b902e8d6e19a7eb51a3e69ece6e79bb432da8 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Sat, 8 Jun 2024 13:14:11 +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 | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 9a683eac8..0a007d816 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -1578,24 +1578,39 @@ void uapi_delete_files(void) int uapi_save_exc(void) { const char *folderPath = "/user/exc"; - const char *tarPath = "/user/tar/exc_%d.tar"; + const char *tarPath = "/user/tar"; + const char *tarfilePath = "/user/tar/exc_%d.tar"; DIR *dir; struct dirent *entry; - mtar_t tar; - char buffer[1024]; - size_t bytesRead = 0; FILE *fp; struct stat file_inf; int ret = 0; + dir = opendir(folderPath); + if (dir == NULL) + { + PRINT("unable to open %s\r\n",folderPath); + return -1; + } + + if(access(tarPath, F_OK) == -1) + { + ret = mkdir(tarPath, 0777); + if(ret == -1) + { + PRINT("mkdir %s failed \r\n",tarPath); + return -1; + } + } + uint32_t timestamp = get_local_timestamp(); char *str = (char *)malloc(200); memset_s(str, 200, 0, 200); - sprintf(str, tarPath, timestamp); + sprintf(str, tarfilePath, timestamp); ret = mtar_open(&tar, str, "w"); if (ret != MTAR_ESUCCESS) @@ -1604,13 +1619,6 @@ int uapi_save_exc(void) return -1; } - dir = opendir(folderPath); - if (dir == NULL) - { - PRINT("unable to open %s\r\n",folderPath); - return -1; - } - while ((entry = readdir(dir)) != NULL) { if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) -- 2.17.1