MCPcopy Index your code
hub / github.com/Microck/opencode-studio / atomicWriteFileSync

Function atomicWriteFileSync

server/index.js:29–55  ·  view source on GitHub ↗
(filePath, data, options = 'utf8')

Source from the content-addressed store, hash-verified

27
28// Atomic file write: write to temp file then rename to prevent corruption
29const atomicWriteFileSync = (filePath, data, options = 'utf8') => {
30 const dir = path.dirname(filePath);
31 if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
32 const tempPath = path.join(dir, `.${path.basename(filePath)}.${crypto.randomBytes(6).toString('hex')}.tmp`);
33 try {
34 fs.writeFileSync(tempPath, data, options);
35 // Retry rename for Windows file locking issues
36 let retries = 5;
37 while (retries > 0) {
38 try {
39 fs.renameSync(tempPath, filePath);
40 break;
41 } catch (e) {
42 if (retries === 1) throw e;
43 retries--;
44 // Synchronous delay
45 const start = Date.now();
46 while (Date.now() - start < 50) {}
47 }
48 }
49 } catch (err) {
50 if (fs.existsSync(tempPath)) {
51 try { fs.unlinkSync(tempPath); } catch (e) {}
52 }
53 throw err;
54 }
55};
56
57const app = express();
58const DEFAULT_PORT = 1920;

Callers 10

saveStudioConfigFunction · 0.85
saveConfigFunction · 0.85
index.jsFile · 0.85
restoreFromBackupFunction · 0.85
saveOhMyOpenCodeConfigFunction · 0.85
savePoolMetadataFunction · 0.85
importCurrentAuthToPoolFunction · 0.85
syncAntigravityPoolFunction · 0.85
rotateAccountFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected