mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-31 17:24:23 +00:00
Merge #11376: Ensure backupwallet fails when attempting to backup to source file
5d465e396 Ensure backupwallet fails when attempting to backup to source file (Tomas van der Wansem) Pull request description: Previous behaviour was to destroy the wallet (to zero-length) This fixes #11375 Tree-SHA512: bfd1738659b15e3f23b6bbdf55ec12269c62c820bf701daec19500b52bd5845bb5516733c6f76f36197eb155182a8a35dc239ad4de2ef1e59bbb0f124a455759
This commit is contained in:
commit
1b8c88451b
@ -705,6 +705,11 @@ bool CWalletDBWrapper::Backup(const std::string& strDest)
|
|||||||
pathDest /= strFile;
|
pathDest /= strFile;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (fs::equivalent(pathSrc, pathDest)) {
|
||||||
|
LogPrintf("cannot backup to wallet source file %s\n", pathDest.string());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fs::copy_file(pathSrc, pathDest, fs::copy_option::overwrite_if_exists);
|
fs::copy_file(pathSrc, pathDest, fs::copy_option::overwrite_if_exists);
|
||||||
LogPrintf("copied %s to %s\n", strFile, pathDest.string());
|
LogPrintf("copied %s to %s\n", strFile, pathDest.string());
|
||||||
return true;
|
return true;
|
||||||
|
@ -190,6 +190,16 @@ class WalletBackupTest(BitcoinTestFramework):
|
|||||||
assert_equal(self.nodes[1].getbalance(), balance1)
|
assert_equal(self.nodes[1].getbalance(), balance1)
|
||||||
assert_equal(self.nodes[2].getbalance(), balance2)
|
assert_equal(self.nodes[2].getbalance(), balance2)
|
||||||
|
|
||||||
|
# Backup to source wallet file must fail
|
||||||
|
sourcePaths = [
|
||||||
|
tmpdir + "/node0/regtest/wallet.dat",
|
||||||
|
tmpdir + "/node0/./regtest/wallet.dat",
|
||||||
|
tmpdir + "/node0/regtest/",
|
||||||
|
tmpdir + "/node0/regtest"]
|
||||||
|
|
||||||
|
for sourcePath in sourcePaths:
|
||||||
|
assert_raises_rpc_error(-4, "backup failed", self.nodes[0].backupwallet, sourcePath)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
WalletBackupTest().main()
|
WalletBackupTest().main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user