fix(oauth): atomic storage writes for token safety

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-08 13:28:14 +09:00
parent 7be285ef89
commit 7ba41d388a
+5 -3
View File
@@ -1,4 +1,4 @@
import { chmodSync, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs"
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs"
import { dirname, join } from "node:path"
import { getOpenCodeConfigDir } from "../../shared"
@@ -82,8 +82,10 @@ function writeStore(store: TokenStore): boolean {
mkdirSync(dir, { recursive: true })
}
writeFileSync(filePath, JSON.stringify(store, null, 2), { encoding: "utf-8", mode: 0o600 })
chmodSync(filePath, 0o600)
const tempPath = `${filePath}.tmp.${Date.now()}`
writeFileSync(tempPath, JSON.stringify(store, null, 2), { encoding: "utf-8", mode: 0o600 })
chmodSync(tempPath, 0o600)
renameSync(tempPath, filePath)
return true
} catch {
return false