The wallet.dat-journal file is SQLite’s hot journal file. This file is either deleted, truncated, or has its header zeroed when a database transaction is committed. However, in restorewallet, we are assuming that sqlite decided to delete the journal file even though it may have truncated or zeroed its header instead.
This PR changes SQLiteDatabase::Close() to remove the journal file if it is 0 bytes, or if the header (first 28 bytes) is all 0’s. Otherwise, it leaves the file untouched.
This fixes one of the issues described in #34354
An alternative is to have RestoreWallet specifically also delete the journal file. However, I thought that this solution would be more robust as I think there are other places where we expect the journal file to be deleted on a clean close of a wallet database.