MCPcopy Create free account
hub / github.com/cortexkit/magic-context / writeFileAtomic

Function writeFileAtomic

packages/cli/src/lib/atomic-write.ts:15–28  ·  view source on GitHub ↗
(targetPath: string, data: string)

Source from the content-addressed store, hash-verified

13 * relying on each call site to remember an ensureDir.
14 */
15export function writeFileAtomic(targetPath: string, data: string): void {
16 mkdirSync(dirname(targetPath), { recursive: true });
17 const tmpPath = `${targetPath}.tmp`;
18 writeFileSync(tmpPath, data, { encoding: "utf-8" });
19 try {
20 if (statSync(targetPath, { throwIfNoEntry: false })?.isFile()) {
21 const mode = statSync(targetPath).mode & 0o777;
22 chmodSync(tmpPath, mode);
23 }
24 } catch {
25 // New file — default umask applies.
26 }
27 renameSync(tmpPath, targetPath);
28}

Callers 12

writePiSettingsPackageFunction · 0.90
writeMagicContextConfigFunction · 0.90
runDoctorFunction · 0.90
addPluginToTuiConfigFunction · 0.90
writeMagicContextConfigFunction · 0.90
writePiSettingsFunction · 0.90
ensurePluginEntryMethod · 0.90
removePluginEntryMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected