(path: string, content: string)
| 73 | * race on the same config file. |
| 74 | */ |
| 75 | export function writeAtomic(path: string, content: string): void { |
| 76 | const tmp = `${path}.tmp.${process.pid}`; |
| 77 | try { |
| 78 | writeFileSync(tmp, content, { encoding: 'utf8', mode: 0o600 }); |
| 79 | renameSync(tmp, path); |
| 80 | } catch (err) { |
| 81 | // Cleanup best effort — if unlink also fails we've already lost; leaving a |
| 82 | // 0o600 tmp of this user's own data is the lesser evil. |
| 83 | try { |
| 84 | unlinkSync(tmp); |
| 85 | } catch { |
| 86 | // swallow |
| 87 | } |
| 88 | throw err; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * One-shot sweep of stale `<filePath>.tmp.<pid>` siblings left behind by a |
no outgoing calls
no test coverage detected