| 674 | } |
| 675 | |
| 676 | bool ChangeLog::archiveExecute(Segment* segment) |
| 677 | { |
| 678 | if (m_config->archiveCommand.hasData()) |
| 679 | { |
| 680 | segment->truncate(); |
| 681 | |
| 682 | auto archiveCommand = m_config->archiveCommand; |
| 683 | |
| 684 | const auto filename = segment->getFileName(); |
| 685 | const auto pathname = m_config->journalDirectory + filename; |
| 686 | |
| 687 | const auto archpathname = m_config->archiveDirectory.hasData() ? |
| 688 | m_config->archiveDirectory + filename : ""; |
| 689 | |
| 690 | size_t pos; |
| 691 | |
| 692 | while ( (pos = archiveCommand.find(FILENAME_WILDCARD)) != string::npos) |
| 693 | archiveCommand.replace(pos, strlen(FILENAME_WILDCARD), filename); |
| 694 | |
| 695 | while ( (pos = archiveCommand.find(PATHNAME_WILDCARD)) != string::npos) |
| 696 | archiveCommand.replace(pos, strlen(PATHNAME_WILDCARD), pathname); |
| 697 | |
| 698 | while ( (pos = archiveCommand.find(ARCHPATHNAME_WILDCARD)) != string::npos) |
| 699 | archiveCommand.replace(pos, strlen(ARCHPATHNAME_WILDCARD), archpathname); |
| 700 | |
| 701 | LockCheckout checkout(this); |
| 702 | |
| 703 | fb_assert(archiveCommand.hasData()); |
| 704 | const auto res = executeShell(archiveCommand); |
| 705 | |
| 706 | if (res) |
| 707 | { |
| 708 | string errorMsg; |
| 709 | |
| 710 | if (res < 0) |
| 711 | { |
| 712 | errorMsg.printf("Cannot execute journal archive command (error %d): %s", |
| 713 | ERRNO, archiveCommand.c_str()); |
| 714 | } |
| 715 | else |
| 716 | { |
| 717 | errorMsg.printf("Unexpected result (%d) while executing journal archive command: %s", |
| 718 | res, archiveCommand.c_str()); |
| 719 | } |
| 720 | |
| 721 | logPrimaryError(m_config->dbName, errorMsg); |
| 722 | return false; |
| 723 | } |
| 724 | } |
| 725 | else if (m_config->archiveDirectory.hasData()) |
| 726 | { |
| 727 | const auto filename = segment->getFileName(); |
| 728 | const auto archpathname = m_config->archiveDirectory + filename; |
| 729 | |
| 730 | struct stat statistics; |
| 731 | if (os_utils::stat(archpathname.c_str(), &statistics) == 0) |
| 732 | { |
| 733 | if (statistics.st_size > (int) sizeof(SegmentHeader)) |
nothing calls this directly
no test coverage detected