| 638 | enum ProcessStatus { PROCESS_SUSPEND, PROCESS_CONTINUE, PROCESS_ERROR, PROCESS_SHUTDOWN }; |
| 639 | |
| 640 | ProcessStatus process_archive(MemoryPool& pool, Target* target) |
| 641 | { |
| 642 | ProcessQueue queue(pool); |
| 643 | |
| 644 | ProcessStatus ret = PROCESS_SUSPEND; |
| 645 | |
| 646 | const auto config = target->getConfig(); |
| 647 | |
| 648 | try |
| 649 | { |
| 650 | // First pass: create the processing queue |
| 651 | |
| 652 | AutoPtr<PathUtils::DirIterator> iter; |
| 653 | |
| 654 | for (iter = PathUtils::newDirIterator(pool, config->sourceDirectory); |
| 655 | *iter; ++(*iter)) |
| 656 | { |
| 657 | if (shutdownFlag) |
| 658 | return PROCESS_SHUTDOWN; |
| 659 | |
| 660 | const auto filename = **iter; |
| 661 | |
| 662 | #ifdef PRESERVE_LOG |
| 663 | PathName path, name; |
| 664 | PathUtils::splitLastComponent(path, name, filename); |
| 665 | |
| 666 | if (name.find('~') == 0) |
| 667 | continue; |
| 668 | #endif |
| 669 | |
| 670 | if (filename.find('{') != PathName::npos && |
| 671 | filename.find('}') != PathName::npos && |
| 672 | filename.find('-') != PathName::npos) |
| 673 | { |
| 674 | continue; |
| 675 | } |
| 676 | |
| 677 | const int fd = os_utils::open(filename.c_str(), O_RDONLY | O_BINARY); |
| 678 | if (fd < 0) |
| 679 | { |
| 680 | if (errno == EACCES || errno == EAGAIN) |
| 681 | { |
| 682 | target->verbose("Skipping file (%s) due to sharing violation", filename.c_str()); |
| 683 | continue; |
| 684 | } |
| 685 | |
| 686 | raiseError("Journal file %s open failed (error: %d)", filename.c_str(), ERRNO); |
| 687 | } |
| 688 | |
| 689 | AutoFile file(fd); |
| 690 | |
| 691 | struct stat stats; |
| 692 | if (fstat(file, &stats) < 0) |
| 693 | raiseError("Journal file %s fstat failed (error: %d)", filename.c_str(), ERRNO); |
| 694 | |
| 695 | const size_t fileSize = stats.st_size; |
| 696 | |
| 697 | if (fileSize < sizeof(SegmentHeader)) |
no test coverage detected