MCPcopy
hub / github.com/OpenCoworkAI/open-codesign / writeAtomic

Function writeAtomic

apps/desktop/src/main/reported-fingerprints.ts:75–90  ·  view source on GitHub ↗
(path: string, content: string)

Source from the content-addressed store, hash-verified

73 * race on the same config file.
74 */
75export function writeAtomic(path: string, content: string): void {
76 const tmp = `${path}.tmp.${process.pid}`;
77 try {
78 writeFileSync(tmp, content, { encoding: 'utf8', mode: 0o600 });
79 renameSync(tmp, path);
80 } catch (err) {
81 // Cleanup best effort — if unlink also fails we've already lost; leaving a
82 // 0o600 tmp of this user's own data is the lesser evil.
83 try {
84 unlinkSync(tmp);
85 } catch {
86 // swallow
87 }
88 throw err;
89 }
90}
91
92/**
93 * One-shot sweep of stale `<filePath>.tmp.<pid>` siblings left behind by a

Callers 2

writeFileFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected