Save wrote state.json.tmp with os.WriteFile and renamed it over state.json without syncing anything. After a power loss or kernel crash the rename could reach the disk before the data, leaving an empty or cut-short state.json. Load cannot parse that, and dnswatcher then stops at every start.
Save now opens the temp file itself, writes it, syncs and closes it, renames it into place, then opens and syncs the data directory so the rename is on disk too. An error from any step is returned, as before.
TestSaveOverLeftoverTempFile starts from a temp file longer than the state Save writes, and checks that afterwards the state file parses with the saved domains and no temp file remains. A test cannot observe a sync: that the file and the directory are synced is confirmed by reading Save.
Rule suppressed: gosec's file-path warning on the temp file's open in Save and on the read in the new test, as Load and the existing tests already do.
Judgement call: the README sentence on atomic writes is unchanged; it stays true.
Model: opus-5-5
Fixes https://git.eeqj.de/sneak/dnswatcher/issues/264.
`Save` wrote `state.json.tmp` with `os.WriteFile` and renamed it over `state.json` without syncing anything. After a power loss or kernel crash the rename could reach the disk before the data, leaving an empty or cut-short `state.json`. `Load` cannot parse that, and dnswatcher then stops at every start.
`Save` now opens the temp file itself, writes it, syncs and closes it, renames it into place, then opens and syncs the data directory so the rename is on disk too. An error from any step is returned, as before.
`TestSaveOverLeftoverTempFile` starts from a temp file longer than the state `Save` writes, and checks that afterwards the state file parses with the saved domains and no temp file remains. A test cannot observe a sync: that the file and the directory are synced is confirmed by reading `Save`.
Rule suppressed: gosec's file-path warning on the temp file's open in `Save` and on the read in the new test, as `Load` and the existing tests already do.
Judgement call: the README sentence on atomic writes is unchanged; it stays true.
Model: opus-5-5
Save wrote state.json.tmp with os.WriteFile and renamed it over
state.json without syncing. After a power loss the rename could reach
the disk before the data, leaving an empty state.json that Load cannot
parse, so every start failed.
Save now writes the temp file through its own handle, syncs and closes
it, renames it, then syncs the data directory so the rename is on disk
too. The new test starts from a leftover temp file longer than the
state; a test cannot observe the syncs, which are confirmed by reading.
Rule suppressed: gosec's file-path warning on the temp file's open, as
Load already does.
Model: opus-5-5
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Fixes #264.
Savewrotestate.json.tmpwithos.WriteFileand renamed it overstate.jsonwithout syncing anything. After a power loss or kernel crash the rename could reach the disk before the data, leaving an empty or cut-shortstate.json.Loadcannot parse that, and dnswatcher then stops at every start.Savenow opens the temp file itself, writes it, syncs and closes it, renames it into place, then opens and syncs the data directory so the rename is on disk too. An error from any step is returned, as before.TestSaveOverLeftoverTempFilestarts from a temp file longer than the stateSavewrites, and checks that afterwards the state file parses with the saved domains and no temp file remains. A test cannot observe a sync: that the file and the directory are synced is confirmed by readingSave.Rule suppressed: gosec's file-path warning on the temp file's open in
Saveand on the read in the new test, asLoadand the existing tests already do.Judgement call: the README sentence on atomic writes is unchanged; it stays true.
Model: opus-5-5
Review: PASS
Model: opus-5-5