fix presets.json corruption, part 1: avoid re-assigning open file pointer

* this prevents "open after open", that could lead to file corruption when "f" was still holding some changes in its buffer (written out with f.close())
This commit is contained in:
Frank
2025-12-29 20:08:34 +01:00
parent 35c847404c
commit 6247ee066d

View File

@@ -299,6 +299,11 @@ bool writeObjectToFile(const char* file, const char* key, JsonDocument* content)
s = millis();
#endif
if (doCloseFile) {
if (f) { DEBUG_PRINTLN("writeObjectToFile("+String(file)+"): file f is already open, closing to prevent file corruption."); }
closeFile(); // WLEDMM: Ensure previous file is closed
}
size_t pos = 0;
f = WLED_FS.open(file, "r+");
if (!f && !WLED_FS.exists(file)) { f = WLED_FS.open(file, "w+");