MCPcopy Create free account
hub / github.com/ElementsProject/elements / Backup

Method Backup

src/wallet/bdb.cpp:605–640  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

603}
604
605bool BerkeleyDatabase::Backup(const std::string& strDest) const
606{
607 while (true)
608 {
609 {
610 LOCK(cs_db);
611 if (m_refcount <= 0)
612 {
613 // Flush log data to the dat file
614 env->CloseDb(strFile);
615 env->CheckpointLSN(strFile);
616
617 // Copy wallet file
618 fs::path pathSrc = env->Directory() / strFile;
619 fs::path pathDest(fs::PathFromString(strDest));
620 if (fs::is_directory(pathDest))
621 pathDest /= fs::PathFromString(strFile);
622
623 try {
624 if (fs::exists(pathDest) && fs::equivalent(pathSrc, pathDest)) {
625 LogPrintf("cannot backup to wallet source file %s\n", fs::PathToString(pathDest));
626 return false;
627 }
628
629 fs::copy_file(pathSrc, pathDest, fs::copy_options::overwrite_existing);
630 LogPrintf("copied %s to %s\n", strFile, fs::PathToString(pathDest));
631 return true;
632 } catch (const fs::filesystem_error& e) {
633 LogPrintf("error copying %s to %s - %s\n", strFile, fs::PathToString(pathDest), fsbridge::get_filesystem_error_message(e));
634 return false;
635 }
636 }
637 }
638 UninterruptibleSleep(std::chrono::milliseconds{100});
639 }
640}
641
642void BerkeleyDatabase::Flush()
643{

Callers 1

BackupWalletMethod · 0.45

Calls 9

PathFromStringFunction · 0.85
existsFunction · 0.85
PathToStringFunction · 0.85
copy_fileFunction · 0.85
UninterruptibleSleepFunction · 0.85
CloseDbMethod · 0.80
CheckpointLSNMethod · 0.80
DirectoryMethod · 0.80

Tested by

no test coverage detected