Save registry inside of scan transaction #2755
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
If you run a
ckan scan
command and Ctrl-C out of it at just the right time (towards the end, I had to add aWriteLine
to get the timing correct), you can end up with a truncatedregistry.json
file:Anything you try to do after this will throw exceptions and generally not work.
Cause
RegistryManager.Save
is transaction-aware:CKAN/Core/Registry/RegistryManager.cs
Lines 413 to 455 in f2209e2
... but
KSP.ScanGameData
calls it outside of its transaction:CKAN/Core/KSP.cs
Lines 409 to 445 in f2209e2
When a
TxFileManager
is used outside of a transaction, it falls back to making live updates to the file system. So if you kill CKAN while it's doing that, it'll just stop after whatever byte happened to be most recently written.Changes
Now
KSP.ScanGameData
saves the registry inside of its transaction. This way if you abort the operation, the originalregistry.json
file will remain intact.Fixes #2754.