Skip to content

Commit d505dcc

Browse files
committed
fix presets.json corruption, part 2: protect deletePresets
deletePreset() also needs to acquire presetFileMux before writing.
1 parent 76cf309 commit d505dcc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

wled00/presets.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,16 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
358358
}
359359

360360
void deletePreset(byte index) {
361+
// WLEDMM Acquire file mutex before writing presets.json, to prevent presets.json corruption
362+
if (esp32SemTake(presetFileMux, 2500) != pdTRUE) {
363+
USER_PRINTLN(F("deletePreset(): preset file busy, cannot write"));
364+
return; // early exit, no change
365+
}
366+
361367
StaticJsonDocument<24> empty;
362368
writeObjectToFileUsingId(getFileName(), index, &empty);
369+
370+
esp32SemGive(presetFileMux); // Release file mutex
363371
presetsModifiedTime = toki.second(); //unix time
364372
updateFSInfo();
365373
}

0 commit comments

Comments
 (0)