Skip to content

Commit 0ec4488

Browse files
committed
adding function to check if a backup exists
1 parent ca5debe commit 0ec4488

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

wled00/cfg.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,10 @@ bool verifyConfig() {
777777
return validateJsonFile(s_cfg_json);
778778
}
779779

780+
bool configBackupExists() {
781+
return checkBackupExists(s_cfg_json);
782+
}
783+
780784
// rename config file and reboot
781785
// if the cfg file doesn't exist, such as after a reset, do nothing
782786
void resetConfig() {

wled00/fcn_declare.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void IRAM_ATTR touchButtonISR();
2727
bool backupConfig();
2828
bool restoreConfig();
2929
bool verifyConfig();
30+
bool configBackupExists();
3031
void resetConfig();
3132
bool deserializeConfig(JsonObject doc, bool fromFS = false);
3233
bool deserializeConfigFromFS();
@@ -103,6 +104,7 @@ inline bool readObjectFromFile(const String &file, const char* key, JsonDocument
103104
bool copyFile(const char* src_path, const char* dst_path);
104105
bool backupFile(const char* filename);
105106
bool restoreFile(const char* filename);
107+
bool checkBackupExists(const char* filename);
106108
bool validateJsonFile(const char* filename);
107109
void dumpFilesToSerial();
108110

wled00/file.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,12 @@ bool restoreFile(const char* filename) {
557557
return false;
558558
}
559559

560+
bool checkBackupExists(const char* filename) {
561+
char backupname[32];
562+
snprintf_P(backupname, sizeof(backupname), s_backup_fmt, filename + 1); // skip leading '/' in filename
563+
return WLED_FS.exists(backupname);
564+
}
565+
560566
bool validateJsonFile(const char* filename) {
561567
if (!WLED_FS.exists(filename)) return false;
562568
File file = WLED_FS.open(filename, "r");

0 commit comments

Comments
 (0)