Skip to content

Keep the last good export until there is a new one - #722

Merged
blaipr merged 1 commit into
mainfrom
fix/keep-the-last-good-export
Aug 13, 2026
Merged

Keep the last good export until there is a new one#722
blaipr merged 1 commit into
mainfrom
fix/keep-the-last-good-export

Conversation

@blaipr

@blaipr blaipr commented Aug 13, 2026

Copy link
Copy Markdown
Member

The bug

XmlExport::export() deleted the previous export before it started writing the new one:

self::deleteExportFiles($exportPath->getPath());   // ← the old one is gone here$this->buildAndSaveXml((string)$file, $password);  // ← and this can throw

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() calls deleteOldBackups() 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.

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.
@blaipr
blaipr merged commit 3a037a4 into main Aug 13, 2026
8 checks passed
@blaipr
blaipr deleted the fix/keep-the-last-good-export branch August 13, 2026 19:55
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