优化tar保存exc文件 251/1 251/head
authorpenglei <1624952103@qq.com>
Sat, 8 Jun 2024 10:34:52 +0000 (18:34 +0800)
committerpenglei <1624952103@qq.com>
Sat, 8 Jun 2024 10:34:52 +0000 (18:34 +0800)
code/sdk/drivers/peripheral/utils/custom_utils.c

index 7bc3292..06e776f 100644 (file)
@@ -1596,6 +1596,15 @@ int uapi_save_exc(void)
     struct stat file_inf;
     int ret = 0;
 
+    if(access(folderPath, F_OK) == -1)
+    {
+        if(ret == -1)
+        {
+            PRINT("%s does not exist!!!\r\n", folderPath);
+            return -1;
+        }
+    }
+
     dir = opendir(folderPath);
     if (dir == NULL) 
     {
@@ -1603,6 +1612,12 @@ int uapi_save_exc(void)
         return -1;
     }
 
+    if((entry = readdir(dir)) == NULL) 
+    {
+        PRINT("%s is empty\r\n",folderPath);
+        return -1;
+    }
+
     if(access(tarPath, F_OK) == -1)
     {
         ret = mkdir(tarPath, 0777); 
@@ -1668,6 +1683,7 @@ int uapi_save_exc(void)
     /* Close archive */
     mtar_close(&tar);
     closedir(dir);
+    removeFilesInFolder(folderPath);
     return ret;
 }