Keep the last good export until there is a new one - #722
Merged
Conversation
The export deleted the previous file before it started writing the new one, so a run that failed part-way — an account it could not read, a failure writing the file — took the last good export with it and left the installation with none. The exception propagated correctly; there was simply nothing left. Delete afterwards instead, skipping the file just written. A successful run still replaces the previous export, and a failed one now leaves it where it was. The test uses a real directory rather than the harness's virtual one: the cleanup uses glob(), which does not see a stream wrapper, so against vfs the test would have passed without proving anything. It fails against the old ordering.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The bug
XmlExport::export()deleted the previous export before it started writing the new one:So a run that failed part-way — an account it could not read, a failure writing the file — took the last good export with it and left the installation with none at all. The exception propagated correctly; there was simply nothing left behind it.
The existing tests already drove four of those failure paths. None of them had a previous export on disk to notice was missing.
The fix
Delete afterwards, skipping the file just written. A successful run still replaces the previous export — the directory does not accumulate every export ever taken — and a failed one leaves it where it was.
Testing
A test that seeds a previous export, makes the run fail, and asserts the previous one is still there. It fails against the old ordering.
It uses a real directory rather than the harness's virtual one, on purpose: the cleanup uses
glob(), which does not see a stream wrapper, so against vfs the test would have passed while proving nothing.The same ordering exists in the backup
BackupFile::doBackup()callsdeleteOldBackups()before writing the new archives, with the same consequence for the database dump and the application archive. It is a larger change — the new archives are named from a hash the delete would also have to skip — and belongs in its own PR rather than being bolted onto this one.