MCPcopy
hub / github.com/Fission-AI/OpenSpec / writeFileAtomically

Function writeFileAtomically

src/core/file-state.ts:99–117  ·  view source on GitHub ↗
(
  filePath: string,
  content: string
)

Source from the content-addressed store, hash-verified

97}
98
99export async function writeFileAtomically(
100 filePath: string,
101 content: string
102): Promise<void> {
103 const dirPath = path.dirname(filePath);
104 await FileSystemUtils.createDirectory(dirPath);
105 const tempPath = path.join(
106 dirPath,
107 `.${path.basename(filePath)}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`
108 );
109
110 try {
111 await fs.writeFile(tempPath, content, 'utf-8');
112 await fs.rename(tempPath, filePath);
113 } catch (error) {
114 await fs.rm(tempPath, { force: true }).catch(() => undefined);
115 throw error;
116 }
117}
118
119export async function acquireFileLock(
120 options: FileLockOptions

Callers 5

file-state.test.tsFile · 0.85
openMethod · 0.85
updateWorksetsStateFunction · 0.85
removeWorksetFunction · 0.85
writeStoreRegistryStateFunction · 0.85

Calls 2

createDirectoryMethod · 0.80
writeFileMethod · 0.80

Tested by

no test coverage detected