| 426 | } |
| 427 | |
| 428 | bool BackupWallet(const CWallet& wallet, const string& strDest) { |
| 429 | while (true) { |
| 430 | { |
| 431 | LOCK(bitdb.cs_db); |
| 432 | if (!bitdb.mapFileUseCount.count(wallet.strWalletFile) || |
| 433 | bitdb.mapFileUseCount[wallet.strWalletFile] == 0) { |
| 434 | // Flush log data to the dat file |
| 435 | bitdb.CloseDb(wallet.strWalletFile); |
| 436 | bitdb.CheckpointLSN(wallet.strWalletFile); |
| 437 | bitdb.mapFileUseCount.erase(wallet.strWalletFile); |
| 438 | |
| 439 | // Copy wallet.dat |
| 440 | boost::filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile; |
| 441 | boost::filesystem::path pathDest(strDest); |
| 442 | if (boost::filesystem::is_directory(pathDest)) |
| 443 | pathDest /= wallet.strWalletFile; |
| 444 | |
| 445 | try { |
| 446 | #if BOOST_VERSION >= 104000 |
| 447 | boost::filesystem::copy_file(pathSrc, pathDest, |
| 448 | boost::filesystem::copy_option::overwrite_if_exists); |
| 449 | #else |
| 450 | boost::filesystem::copy_file(pathSrc, pathDest); |
| 451 | #endif |
| 452 | LogPrint(BCLog::INFO, "copied wallet.dat into %s\n", pathDest.string()); |
| 453 | return true; |
| 454 | } catch (const boost::filesystem::filesystem_error& e) { |
| 455 | LogPrint(BCLog::ERROR, "error copying wallet.dat into %s - %s\n", pathDest.string(), e.what()); |
| 456 | return false; |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | MilliSleep(100); |
| 461 | } |
| 462 | return false; |
| 463 | } |
no test coverage detected