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:
@@ -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+");
|
||||
|
||||
Reference in New Issue
Block a user