Skip to content

fix(storage): write vault files atomically to avoid truncation on failure - #985

Merged
antonreshetov merged 1 commit into
mainfrom
fix/atomic-vault-writes
Oct 14, 2026
Merged

antonreshetov merged 1 commit into
mainfrom
fix/atomic-vault-writes

Conversation

@antonreshetov

Copy link
Copy Markdown
Member

Notes, snippets, HTTP requests, folder .meta.yaml, state.json / .state.yaml and doctor id fixes were written with fs.writeFileSync over the existing file. It truncates first, so ENOSPC/EIO in the middle of a write left a cut-off file on disk even though the runtime rolled back.

  • Add writeFileAtomicSync in runtime/shared/atomicWrite.ts: write a hidden .<name>.<hex>.tmp next to the target, then renameSync over it. Preserves the file mode, writes through symlinks, removes the temp file on failure, falls back to an in-place write on Windows when the target is locked by another process.
  • Use it in all vault writers listed above.
  • Tests: unit tests for the helper, partial-write and failed-rename cases for notes and snippets; path-keyed write mocks moved to renameSync.

Checked on a real iCloud Drive vault with the dev build: repeated saves, rename/move, external edits picked up by the watcher, upload without conflicts, content verified after eviction, edits blocked until a dataless note is downloaded.

@antonreshetov antonreshetov self-assigned this Oct 14, 2026
@antonreshetov
antonreshetov merged commit 1b68763 into main Oct 14, 2026
@antonreshetov
antonreshetov deleted the fix/atomic-vault-writes branch October 14, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant