Repository navigation
Commit 40d2b4d
authored
fix(settings): write settings file atomically via temp + rename (#285)
## Problem
`BaseSettings._save` (`sendspin/settings.py`, shared by client and serve
settings) rewrites the live JSON file in place with `write_text`. A kill
mid-write truncates it, and on next start the `JSONDecodeError` handler
logs a warning and silently falls back to defaults -- volume, name,
interface and hooks all revert with no obvious cause.
## Fix
Write-temp-then-rename: content goes to a `.tmp` sibling, is fsynced,
then `os.replace()` swaps it into place atomically. A crash can now only
leave the previous good file behind. Same `OSError` handling as before.
## Verification
- Full suite (`pytest tests/`, excluding serve + audio_devices): 123
passed
- `ruff check` clean
Covers both `ClientSettings` and `ServeSettings` since they share
`_save`.1 parent 2139ed7 commit 40d2b4d
1 file changed
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
109 | 115 | | |
110 | 116 | | |
111 | 117 | | |
| |||
0 commit comments