Minimal fix for #34128. This is the first part of a series of changes.
The issue occurs during the migration of a legacy unnamed wallet
(the legacy “default” wallet). When the migration fails, the cleanup
logic is triggered to roll back the state, which involves erasing the
newly created descriptor wallets directories. Normally, this only
affects the parent directories of named wallets, since they each
reside in their own directories. However, because the unnamed
wallet resides directly in the top-level /wallets/ folder, this
logic accidentally deletes the main directory.
The fix ensures that only the wallet.dat file of the unnamed wallet
is touched and restored, preserving the wallet in BDB format and
leaving the main /wallets/ directory intact.
Testing Notes: Cherry-pick the test commit on top of master and run it. You will see the failure and realize the reason by reading the test code.
Important Note: I’m pushing it early to alert users and start discussing the solution. As written on the first sentence, this is a minimal fix, and further improvements are possible (and planned). For example, files removal could be specialized as in b78990734621b8fe46c68a6e7edaf1fbd2f7d351, but additional changes are needed to implement it.