Skip to content

fix(storage): prevent vault data loss on corruption or truncated JSON - #211

Merged
Cleboost merged 4 commits into
masterfrom
fix/vault-corruption-recovery
Nov 26, 2026
Merged

Cleboost merged 4 commits into
masterfrom
fix/vault-corruption-recovery

Conversation

@Cleboost

Copy link
Copy Markdown
Owner

Summary

  • Atomic writes (write_secure): write to a temporary file in the same directory, call sync_all(), apply 0o600 permissions on Unix, and atomically rename onto the target path.
  • Automatic .bak backup: save_plain_vault backs up the previous valid vault to <filename>.bak before overwriting.
  • Fallback & partial recovery (load_plain_vault):
    • Falls back to <filename>.bak if the primary vault file is missing or corrupted.
    • If no valid backup is available, recover_truncated_plain_vault extracts all complete Host and Group entries from truncated JSON.
    • Quarantines the corrupted file as <filename>.corrupted.<timestamp> instead of overwriting it.

Testing

  • cargo test storage::store: 4/4 tests passing (including backup fallback and truncated JSON recovery).

@Cleboost
Cleboost merged commit ab05964 into master Nov 26, 2026
@Cleboost
Cleboost deleted the fix/vault-corruption-recovery branch November 26, 2026 19:46
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