mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 23:08:11 +00:00
saveContacts/saveChannels/savePrefs truncated the live file up front and then wrote in place, so a crash, reset or full flash mid-save wiped the whole file — observed as all contacts disappearing after a UI hang. Write to a temp file and only swap it in (via LittleFS atomic rename) once every record has written cleanly; on any failure keep the previous good file and drop the temp. savePrefs gates the swap on the tail-sentinel write succeeding (writes return 0 once flash fills, so a good sentinel means the whole record fit). Contacts/channels live on the multi-MB QSPIFlash, so the transient second copy fits easily. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>