( filePath: string, state: CacheStatsState, )
| 94 | * partial-write corruption and concurrent reads. |
| 95 | */ |
| 96 | export async function writeStateAtomic( |
| 97 | filePath: string, |
| 98 | state: CacheStatsState, |
| 99 | ): Promise<void> { |
| 100 | const dir = dirname(filePath) |
| 101 | await mkdir(dir, { recursive: true }) |
| 102 | const tmp = `${filePath}.${process.pid}.tmp` |
| 103 | try { |
| 104 | await writeFile(tmp, JSON.stringify(state), 'utf8') |
| 105 | await rename(tmp, filePath) |
| 106 | } catch { |
| 107 | // Best-effort; silently ignore errors so the UI never crashes |
| 108 | } |
| 109 | } |
no test coverage detected