<!-- Pull requests without a rationale and clear improvement may be closed immediately. -->
This makes bitcoin-wallet dump fail if writing the dump file does not complete successfully.
Previously, DumpWallet() only checked whether the dump file could be opened. If later writes or close failed, the tool could still return success and print the private-key warning, leaving a truncated dump file behind.
The change adds write/close checks while dumping wallet records. If writing fails, the partial dump file is removed and bitcoin-wallet returns an error.
The functional test now covers a forced incomplete dump on POSIX systems by limiting the dump process file size. It checks that:
- stdout stays empty;
- the command exits with failure;
- the write error is reported;
- the partial dump file is removed.
Tested with:
cmake -S /tmp/bitcoin-core-wallet-dump-pr -B /tmp/bitcoin-core-wallet-dump-pr-build -DBUILD_TESTS=OFF -DBUILD_BENCH=OFF -DBUILD_GUI=OFF -DENABLE_WALLET=ON -DBUILD_WALLET_TOOL=ON -DENABLE_IPC=OFF -DWITH_ZMQ=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build /tmp/bitcoin-core-wallet-dump-pr-build --target bitcoind bitcoin-wallet -j"$(sysctl -n hw.ncpu)"
python3 test/functional/tool_wallet.py --configfile=/tmp/bitcoin-core-wallet-dump-pr-build/test/config.ini