MCPcopy Create free account
hub / github.com/EvoMap/evolver / replaceStateFile

Function replaceStateFile

src/proxy/mailbox/state.js:128–142  ·  view source on GitHub ↗
(stateFile, state)

Source from the content-addressed store, hash-verified

126}
127
128function replaceStateFile(stateFile, state) {
129 const dir = path.dirname(stateFile);
130 ensurePrivateDir(dir);
131 const tmp = `${stateFile}.${process.pid}.tmp`;
132 writePrivateFile(tmp, JSON.stringify(state || {}, null, 2) + '\n');
133 // Windows: renameSync throws EPERM when the destination file already
134 // exists, unlike POSIX where rename(2) atomically replaces the target.
135 if (process.platform === 'win32') {
136 try { fs.unlinkSync(stateFile); } catch (e) {
137 if (e.code !== 'ENOENT') throw e;
138 }
139 }
140 fs.renameSync(tmp, stateFile);
141 bestEffortChmod(stateFile, PRIVATE_FILE_MODE);
142}
143
144/**
145 * Merge a partial state write with the latest on-disk state.

Callers 1

Calls 3

ensurePrivateDirFunction · 0.85
writePrivateFileFunction · 0.85
bestEffortChmodFunction · 0.85

Tested by

no test coverage detected