From 613c0f81c67254a4d31666c7ba80f1879492690f Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Tue, 11 Jun 2024 17:45:54 +0800 Subject: [PATCH] =?utf8?q?=E6=B7=BB=E5=8A=A0tar=E4=BF=9D=E5=AD=98=E6=96=87?= =?utf8?q?=E4=BB=B6=E9=80=9A=E7=94=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../drivers/peripheral/utils/custom_utils.c | 77 +++++++++++-------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index c6aab10dc..2fce0a257 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -298,12 +298,6 @@ void startup_post_init_task(void) uapi_calendar_recover_date(); - int ret = uapi_save_exc(); - if(ret != 0) - PRINT("exc file save failed \r\n"); - else - PRINT("exc file save succed \r\n"); - if(!custom_ble_service_on_flag()) { stop_custom_ble_service(); @@ -320,6 +314,16 @@ void startup_post_init_task(void) //initializeMotionRecognition(); LOS_Msleep(5000); + + int ret = uapi_save_exc(); + if(ret != 0) + PRINT("exc file save failed \r\n"); + else + { + PRINT("exc file save succed \r\n"); + removeFilesInFolder("/user/exc"); + } + addressbookToRead(NULL); up_report_timer(); if ( poweron_cat1_on_bootup_flag() ) @@ -1613,12 +1617,9 @@ void uapi_delete_files(void) } } -int uapi_save_exc(void) +int uapi_tar_file(const char *src_path,const char *tar_path,char *tarfilename) { - const char *folderPath = "/user/exc"; - const char *tarPath = "/user/tar"; - const char *tarfilePath = "/user/tar/exc_%d.tar"; - + //const char *tarfilePath = "%s/exc_%d.tar"; DIR *dir; struct dirent *entry; mtar_t tar; @@ -1626,44 +1627,40 @@ int uapi_save_exc(void) size_t bytesRead = 0; FILE *fp; struct stat file_inf; + long tar_size = 0; int ret = 0; - if(access(folderPath, F_OK) == -1) + if(access(src_path, F_OK) == -1) { if(ret == -1) { - PRINT("%s does not exist!!!\r\n", folderPath); + PRINT("%s does not exist!!!\r\n", src_path); return -1; } } - dir = opendir(folderPath); + dir = opendir(src_path); if (dir == NULL) { - PRINT("unable to open %s\r\n",folderPath); + PRINT("unable to open %s\r\n",src_path); return -1; } - if((entry = readdir(dir)) == NULL) + if(access(tar_path, F_OK) == -1) { - PRINT("%s is empty\r\n",folderPath); - return -1; - } - - if(access(tarPath, F_OK) == -1) - { - ret = mkdir(tarPath, 0777); + ret = mkdir(tar_path, 0777); if(ret == -1) { - PRINT("mkdir %s failed \r\n",tarPath); + PRINT("mkdir %s failed \r\n",tar_path); return -1; } } - uint32_t timestamp = get_local_timestamp(); - char *str = (char *)malloc(200); - memset_s(str, 200, 0, 200); - sprintf(str, tarfilePath, timestamp); + char str[200] = {0}; + //snprintf(str, sizeof(str), tar_path,tarfilePath,timestamp); + sprintf(str, "%s/%s",tar_path,tarfilename); + PRINT("str %s \r\n",str); + //sprintf(str, tarfilePath, timestamp); ret = mtar_open(&tar, str, "w"); if (ret != MTAR_ESUCCESS) @@ -1677,7 +1674,7 @@ 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", folderPath, entry->d_name); + snprintf(filePath, sizeof(filePath), "%s/%s", src_path, entry->d_name); fp = fopen(filePath, "r"); if(fp == NULL) @@ -1688,7 +1685,7 @@ int uapi_save_exc(void) memset(&file_inf, 0, sizeof(file_inf)); stat(filePath, &file_inf); - + tar_size += file_inf.st_size; mtar_write_file_header(&tar, entry->d_name, file_inf.st_size); while((bytesRead = fread(buffer, 1, sizeof(buffer), fp)) > 0) @@ -1708,17 +1705,33 @@ int uapi_save_exc(void) } } } - + /* Finalize -- this needs to be the last thing done before closing */ mtar_finalize(&tar); /* Close archive */ mtar_close(&tar); closedir(dir); - removeFilesInFolder(folderPath); + if(tar_size == 0) + { + PRINT("%s is empty\r\n",src_path); + remove(str); + return -1; + } + //free(str); return ret; } + +int uapi_save_exc(void) +{ + uint32_t timestamp = get_local_timestamp(); + char *tarfilePath = "exc_%d.tar"; + char str[200] = {0}; + sprintf(str, tarfilePath, timestamp); + return uapi_tar_file("/user/exc","/user/tar",str); +} + #include "driver/calendar.h" uint32_t uapi_calendar_store_date(void) -- 2.17.1