Skip to content

fix(storage): move entity file back when write after rename fails - #984

Merged
antonreshetov merged 1 commit into
mainfrom
fix/rollback-entity-move-on-write-failure
Oct 14, 2026
Merged

antonreshetov merged 1 commit into
mainfrom
fix/rollback-entity-move-on-write-failure

Conversation

@antonreshetov

Copy link
Copy Markdown
Member

updateNote / updateSnippet mutated runtime fields, moved or renamed the file and updated the state index before writing frontmatter. If the write failed after the move (EACCES/ENOSPC), runtime and the deferred state index pointed to the new path while disk kept old frontmatter there.

  • persistNote / persistSnippet: on write failure, move the file back and restore filePath and the state index (a failed createNote no longer leaves an index entry without a file). If moving back fails, runtime stays on the actual path.
  • updateNote / updateSnippet and folder deletion: restore entity fields via persistOrRestore.
  • applyEntityUpdateFields: validate the target folder before any mutation and return a snapshot of previous values instead of previousIsDeleted.
  • Tests with vi.spyOn(fs, 'writeFileSync') for notes, snippets and applyEntityUpdateFields.

@antonreshetov antonreshetov self-assigned this Oct 14, 2026
@antonreshetov
antonreshetov merged commit 81dfd0f into main Oct 14, 2026
@antonreshetov
antonreshetov deleted the fix/rollback-entity-move-on-write-failure branch October 14, 2026 06:47
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