Atomic write of a threads file at an explicit path. Used by saveThreadIndex * and by legacy-global-file maintenance in the migration code below.
(filePath: string, index: ThreadIndex)
| 102 | /** Atomic write of a threads file at an explicit path. Used by saveThreadIndex |
| 103 | * and by legacy-global-file maintenance in the migration code below. */ |
| 104 | function writeThreadsFileAt(filePath: string, index: ThreadIndex): void { |
| 105 | const dir = dirname(filePath); |
| 106 | if (!existsSync(dir)) mkdirSync(dir, { recursive: true, mode: 0o700 }); |
| 107 | const tmpPath = filePath + ".tmp"; |
| 108 | writeFileSync(tmpPath, JSON.stringify(index, null, 2), { mode: 0o600 }); |
| 109 | renameSync(tmpPath, filePath); |
| 110 | } |
| 111 | |
| 112 | export function saveThreadIndex(stateDir: string, index: ThreadIndex): void { |
| 113 | writeThreadsFileAt(threadsFilePath(stateDir), index); |
no outgoing calls
no test coverage detected