fix presets.json corruption, part 2: protect deletePresets

deletePreset() also needs to acquire presetFileMux before writing.
This commit is contained in:
Frank
2025-12-29 21:02:06 +01:00
parent 76cf309373
commit d505dcc6a8

View File

@@ -358,8 +358,16 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
}
void deletePreset(byte index) {
// WLEDMM Acquire file mutex before writing presets.json, to prevent presets.json corruption
if (esp32SemTake(presetFileMux, 2500) != pdTRUE) {
USER_PRINTLN(F("deletePreset(): preset file busy, cannot write"));
return; // early exit, no change
}
StaticJsonDocument<24> empty;
writeObjectToFileUsingId(getFileName(), index, &empty);
esp32SemGive(presetFileMux); // Release file mutex
presetsModifiedTime = toki.second(); //unix time
updateFSInfo();
}