| 752 | } |
| 753 | |
| 754 | bool BerkeleyDatabase::Backup(const std::string& strDest) |
| 755 | { |
| 756 | if (IsDummy()) { |
| 757 | return false; |
| 758 | } |
| 759 | while (true) |
| 760 | { |
| 761 | { |
| 762 | LOCK(cs_db); |
| 763 | if (!env->mapFileUseCount.count(strFile) || env->mapFileUseCount[strFile] == 0) |
| 764 | { |
| 765 | // Flush log data to the dat file |
| 766 | env->CloseDb(strFile); |
| 767 | env->CheckpointLSN(strFile); |
| 768 | env->mapFileUseCount.erase(strFile); |
| 769 | |
| 770 | // Copy wallet file |
| 771 | fs::path pathSrc = env->Directory() / strFile; |
| 772 | fs::path pathDest(strDest); |
| 773 | if (fs::is_directory(pathDest)) |
| 774 | pathDest /= strFile; |
| 775 | |
| 776 | try { |
| 777 | if (fs::equivalent(pathSrc, pathDest)) { |
| 778 | LogPrintf("cannot backup to wallet source file %s\n", pathDest.string()); |
| 779 | return false; |
| 780 | } |
| 781 | |
| 782 | fs::copy_file(pathSrc, pathDest, fs::copy_option::overwrite_if_exists); |
| 783 | LogPrintf("copied %s to %s\n", strFile, pathDest.string()); |
| 784 | return true; |
| 785 | } catch (const fs::filesystem_error& e) { |
| 786 | LogPrintf("error copying %s to %s - %s\n", strFile, pathDest.string(), e.what()); |
| 787 | return false; |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | MilliSleep(100); |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | void BerkeleyDatabase::Flush(bool shutdown) |
| 796 | { |
no test coverage detected