MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / BackupWallet

Function BackupWallet

src/wallet/walletdb.cpp:428–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426}
427
428bool 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}

Callers 1

backupwalletFunction · 0.85

Calls 6

MilliSleepFunction · 0.85
CloseDbMethod · 0.80
CheckpointLSNMethod · 0.80
countMethod · 0.45
eraseMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected