rotation of image log files implemented

improved rotation of message log files
implement deletion of temp images before start new flow
a little bit code cleaning
This commit is contained in:
Jurij Retzlaff
2020-11-12 23:27:00 +01:00
parent acc7253ca1
commit f4f871002b
21 changed files with 259 additions and 123 deletions

View File

@@ -3,7 +3,9 @@
#include "Helper.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <string.h>
#include <esp_log.h>
//#define ISWINDOWS_TRUE
#define PATH_MAX_STRING_SIZE 256
@@ -239,4 +241,37 @@ time_t addDays(time_t startTime, int days) {
struct tm* tm = localtime(&startTime);
tm->tm_mday += days;
return mktime(tm);
}
}
int removeFolder(const char* folderPath, const char* logTag) {
ESP_LOGI(logTag, "Delete folder %s", folderPath);
DIR *dir = opendir(folderPath);
if (!dir) {
ESP_LOGI(logTag, "Failed to stat dir : %s", folderPath);
return -1;
}
struct dirent *entry;
int deleted = 0;
while ((entry = readdir(dir)) != NULL) {
std::string path = string(folderPath) + "/" + entry->d_name;
if (entry->d_type == DT_REG) {
if (unlink(path.c_str()) == 0) {
deleted ++;
} else {
ESP_LOGE(logTag, "can't delete file : %s", path.c_str());
}
} else if (entry->d_type == DT_DIR) {
deleted += removeFolder(path.c_str(), logTag);
}
}
closedir(dir);
if (rmdir(folderPath) != 0) {
ESP_LOGE(logTag, "can't delete file : %s", folderPath);
}
ESP_LOGI(logTag, "%d older log files in folder %s deleted.", deleted, folderPath);
return deleted;
}