(path: string, data: string)
| 8 | * write that overwrites an existing user-owned file. |
| 9 | */ |
| 10 | export async function atomicWrite(path: string, data: string): Promise<void> { |
| 11 | const tmp = `${path}.${process.pid}.tmp`; |
| 12 | // Migrated config/MCP files can carry provider API keys. Create them |
| 13 | // private (0600) so they are never group/world-readable, even when the |
| 14 | // target home directory itself has permissive permissions. `chmod` covers |
| 15 | // the case where a stale temp file from a crashed run already exists. |
| 16 | await writeFile(tmp, data, { encoding: 'utf-8', mode: 0o600 }); |
| 17 | await chmod(tmp, 0o600); |
| 18 | await rename(tmp, path); |
| 19 | } |
no test coverage detected