MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / writeFileAtomic

Function writeFileAtomic

apps/desktop/src/main/vault.ts:646–670  ·  view source on GitHub ↗
(absPath: string, data: string)

Source from the content-addressed store, hash-verified

644 * user's data and are just clutter.
645 */
646export async function writeFileAtomic(absPath: string, data: string): Promise<void> {
647 const tmp = `${absPath}.${process.pid}.${Date.now()}.tmp`
648 await fs.mkdir(path.dirname(absPath), { recursive: true })
649 const handle = await fs.open(tmp, 'w')
650 try {
651 await handle.writeFile(data, 'utf8')
652 try {
653 await handle.sync()
654 } catch (syncErr) {
655 console.warn('fsync failed for atomic write', syncErr)
656 }
657 } finally {
658 await handle.close()
659 }
660 try {
661 await fs.rename(tmp, absPath)
662 } catch (err) {
663 try {
664 await fs.unlink(tmp)
665 } catch {
666 /* ignore */
667 }
668 throw err
669 }
670}
671
672export async function updateConfig(
673 updater: (cfg: PersistedConfig) => PersistedConfig | Promise<PersistedConfig>

Callers 8

persistSidecarFunction · 0.90
readDatabaseFunction · 0.90
writeDatabaseRowsFunction · 0.90
writeDatabaseSchemaFunction · 0.90
createDatabaseFunction · 0.90
initAppConfigFunction · 0.90
setPortableConfigFunction · 0.90
migrateOneLegacyDatabaseFunction · 0.85

Calls 1

closeMethod · 0.45

Tested by

no test coverage detected