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

Function cleanupStaleConfigTmpFiles

apps/desktop/src/main/vault.ts:563–588  ·  view source on GitHub ↗

Removes orphaned ` . . .tmp` files left behind when a * previous save was interrupted between `fs.open` and `fs.rename`. Best * effort — a missing parent dir or unreadable entries are not fatal.

()

Source from the content-addressed store, hash-verified

561 * previous save was interrupted between `fs.open` and `fs.rename`. Best
562 * effort — a missing parent dir or unreadable entries are not fatal. */
563async function cleanupStaleConfigTmpFiles(): Promise<void> {
564 const dir = path.dirname(configPath())
565 const prefix = `${path.basename(configPath())}.`
566 let entries: Dirent[]
567 try {
568 entries = await fs.readdir(dir, { withFileTypes: true })
569 } catch {
570 return
571 }
572 await Promise.all(
573 entries
574 .filter(
575 (entry) =>
576 entry.isFile() &&
577 entry.name.startsWith(prefix) &&
578 CONFIG_TMP_SUFFIX_RE.test(entry.name)
579 )
580 .map(async (entry) => {
581 try {
582 await fs.unlink(path.join(dir, entry.name))
583 } catch {
584 /* ignore */
585 }
586 })
587 )
588}
589
590/** Persists the config atomically: write to a temp file, fsync, then rename
591 * over the live file. Before the rename, the previous live file is copied

Callers 1

saveConfigFunction · 0.85

Calls 1

configPathFunction · 0.85

Tested by

no test coverage detected