补交 244/3
authorpenglei <1624952103@qq.com>
Sat, 8 Jun 2024 05:14:11 +0000 (13:14 +0800)
committerpenglei <1624952103@qq.com>
Sat, 8 Jun 2024 05:14:11 +0000 (13:14 +0800)
code/sdk/drivers/peripheral/utils/custom_utils.c

index 9a683ea..0a007d8 100644 (file)
@@ -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)