fix(config): use canonical path after legacy migration and make writes atomic

This commit is contained in:
YeonGyu-Kim
2026-04-04 14:33:52 +09:00
parent 2d72f51a92
commit 0c6907adc3
6 changed files with 80 additions and 39 deletions
+13
View File
@@ -0,0 +1,13 @@
import { closeSync, fsyncSync, openSync, renameSync, writeFileSync } from "node:fs"
export function writeFileAtomically(filePath: string, content: string): void {
const tempPath = `${filePath}.tmp`
writeFileSync(tempPath, content, "utf-8")
const tempFileDescriptor = openSync(tempPath, "r")
try {
fsyncSync(tempFileDescriptor)
} finally {
closeSync(tempFileDescriptor)
}
renameSync(tempPath, filePath)
}