| 603 | } |
| 604 | |
| 605 | bool 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 | |
| 642 | void BerkeleyDatabase::Flush() |
| 643 | { |
no test coverage detected