Skip to content

Recover corrupt versioned stores instead of crashing - #172

Merged
xxfast merged 2 commits into
masterfrom
ir/versioned-codec-corrupt-file
Aug 4, 2026
Merged

Recover corrupt versioned stores instead of crashing#172
xxfast merged 2 commits into
masterfrom
ir/versioned-codec-corrupt-file

Conversation

@xxfast

@xxfast xxfast commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Decoding a corrupt or partially written versioned store crashes instead of falling back to the migration. VersionedCodec.decode re-reads the version file and the raw data inside its own catch block with nothing guarding either, so an empty or truncated file throws straight back out. Reported three times: #80, #157, #162.

A missing version file still reads as 0 like before, an unreadable one now reads as null, which Migration<T> already allows for. Nothing that works today changes behaviour.

Also ports the moveOrCopy fallback from #159 into encode, which still called atomicMove directly and so never got fixed for versioned stores on Android 7 and below.

  • Fix KVersionedStore to handle corrupt or partially written files gracefully

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.26%. Comparing base (6a52682) to head (c71362e).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #172      +/-   ##
==========================================
+ Coverage   92.68%   94.26%   +1.57%     
==========================================
  Files           8        8              
  Lines         123      122       -1     
  Branches       12       11       -1     
==========================================
+ Hits          114      115       +1     
+ Misses          1        0       -1     
+ Partials        8        7       -1     
Files with missing lines Coverage Δ
...b/xxfast/kstore/file/extensions/KVersionedStore.kt 100.00% <100.00%> (+5.26%) ⬆️

@xxfast
xxfast force-pushed the ir/versioned-codec-corrupt-file branch from 2c40174 to c71362e Compare August 4, 2026 18:51
@xxfast
xxfast marked this pull request as ready for review August 4, 2026 18:52
@xxfast
xxfast merged commit fdc1b10 into master Aug 4, 2026
8 checks passed
@xxfast
xxfast deleted the ir/versioned-codec-corrupt-file branch August 4, 2026 18:59
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