Expand description
Atomic JSON file writes shared by every on-disk config the project
maintains (preferences.json, hardware.json, per-dashboard files
under dashboards/).
The pattern is the same every time:
mkdir -pthe parent.- Open a per-process-unique sibling
.tmp.<pid>.<counter>withO_CREAT|O_EXCLso two writers can’t trample each other. - Write the serialized body, then
fsync(2)so the bytes hit stable storage before the rename swaps the inode. rename(2)onto the final path. On rename failure clean up the tmp sibling so it doesn’t accumulate.
Living in linsight-core means the daemon’s NicknameStore, the
GUI’s PreferencesModel, and the dashboards storage all share one
tested implementation — diverging behavior (e.g., one of them
missing the fsync, another missing the cleanup) caused minor bugs
before this lift.
Functions§
- atomic_
write_ json - Serialize
valueas pretty JSON and write it topathatomically. Errors propagate asstd::io::Error(serialization errors are wrapped viaError::other). Use?to surface them; the caller decides whether to log / retry / abort.