// void save_popup_windows_log_c(int type){}
// void system_init_uart(void){}
#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <dirent.h>
+#include <sys/stat.h>
#include <unistd.h>
#include "custom_runtime.h"
#include "pm_definition.h"
}
+/*删除文件夹*/
+int uapi_delete_folder(const char *folder_path) {
+ // 参数检查
+ if (folder_path == NULL || strlen(folder_path) == 0) {
+ fprintf(stderr, "Error: Invalid folder path\n");
+ return -1;
+ }
+
+ // 安全检查:防止删除根目录
+ if (strcmp(folder_path, "/") == 0 ||
+ strcmp(folder_path, ".") == 0 ||
+ strcmp(folder_path, "..") == 0) {
+ fprintf(stderr, "Error: Deleting root directory or current/parent directory is prohibited\n");
+ return -1;
+ }
+
+ // 检查路径是否存在
+ struct stat statbuf;
+ if (stat(folder_path, &statbuf) != 0) {
+ // 路径不存在,可能已被删除,视为成功
+ return 0;
+ }
+
+ // 如果不是目录,返回错误
+ if (!S_ISDIR(statbuf.st_mode)) {
+ fprintf(stderr, "Error: Path '%s' is not a directory\n", folder_path);
+ return -1;
+ }
+
+ // 打开目录
+ DIR *dir = opendir(folder_path);
+ if (dir == NULL) {
+ fprintf(stderr, "Error: Failed to open directory '%s'\n", folder_path);
+ return -1;
+ }
+
+ // 递归删除目录中的所有内容
+ struct dirent *entry;
+ char subpath[1024]; // 假设路径长度不超过1024字节
+
+ while ((entry = readdir(dir)) != NULL) {
+ // 跳过当前目录和上级目录
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
+ continue;
+ }
+
+ // 构建子路径
+ snprintf(subpath, sizeof(subpath), "%s/%s", folder_path, entry->d_name);
+
+ // 获取子项信息
+ if (stat(subpath, &statbuf) != 0) {
+ fprintf(stderr, "Warning: Failed to stat '%s', skipping\n", subpath);
+ continue;
+ }
+
+ // 如果是目录,递归删除
+ if (S_ISDIR(statbuf.st_mode)) {
+ if (uapi_delete_folder(subpath) != 0) {
+ fprintf(stderr, "Error: Failed to delete subdirectory '%s'\n", subpath);
+ closedir(dir);
+ return -1;
+ }
+ }
+ // 如果是文件或符号链接,直接删除
+ else {
+ if (unlink(subpath) != 0) {
+ fprintf(stderr, "Error: Failed to delete file '%s'\n", subpath);
+ closedir(dir);
+ return -1;
+ }
+ }
+ }
+
+ // 关闭目录
+ closedir(dir);
+
+ // 删除空目录
+ if (rmdir(folder_path) != 0) {
+ fprintf(stderr, "Error: Failed to remove directory '%s'\n", folder_path);
+ return -1;
+ }
+
+ return 0; // 成功
+}
+
void uapi_check_tar_file_count(char *folderpath)
{
DIR *dir;