MCPcopy Index your code
hub / github.com/anomalyco/opencode / writeJsonAtomic

Function writeJsonAtomic

packages/tui/src/util/persistence.ts:22–33  ·  view source on GitHub ↗
(filePath: string, value: unknown)

Source from the content-addressed store, hash-verified

20}
21
22export async function writeJsonAtomic(filePath: string, value: unknown) {
23 await mkdir(path.dirname(filePath), { recursive: true })
24 const temporary = `${filePath}.${process.pid}.${crypto.randomUUID()}.tmp`
25 await Bun.write(temporary, JSON.stringify(value)).catch(async (error) => {
26 await rm(temporary, { force: true }).catch(() => undefined)
27 throw error
28 })
29 await rename(temporary, filePath).catch(async (error) => {
30 await rm(temporary, { force: true }).catch(() => undefined)
31 throw error
32 })
33}

Callers 3

setFunction · 0.90
saveFunction · 0.90

Calls 3

renameFunction · 0.85
writeMethod · 0.80
rmFunction · 0.50

Tested by

no test coverage detected