fgerlits commented on a change in pull request #791:
URL: https://github.com/apache/nifi-minifi-cpp/pull/791#discussion_r435308929



##########
File path: extensions/standard-processors/processors/TailFile.cpp
##########
@@ -335,65 +387,45 @@ bool TailFile::storeState(const 
std::shared_ptr<core::ProcessContext>& context)
   return true;
 }
 
-static bool sortTailMatchedFileItem(TailMatchedFileItem i, TailMatchedFileItem 
j) {
-  return (i.modifiedTime < j.modifiedTime);
-}
-void TailFile::checkRollOver(const std::shared_ptr<core::ProcessContext>& 
context, TailState &file, const std::string &base_file_name) {
-  struct stat statbuf;
-  std::vector<TailMatchedFileItem> matchedFiles;
-  std::string fullPath = file.path_ + utils::file::FileUtils::get_separator() 
+ file.current_file_name_;
-
-  if (stat(fullPath.c_str(), &statbuf) == 0) {
-    logger_->log_trace("Searching for files rolled over");
-    std::string pattern = file.current_file_name_;
-    std::size_t found = file.current_file_name_.find_last_of(".");
-    if (found != std::string::npos)
-      pattern = file.current_file_name_.substr(0, found);
-
-    // Callback, called for each file entry in the listed directory
-    // Return value is used to break (false) or continue (true) listing
-    auto lambda = [&](const std::string& path, const std::string& filename) -> 
bool {
-      struct stat sb;
-      std::string fileFullName = path + 
utils::file::FileUtils::get_separator() + filename;
-      if ((fileFullName.find(pattern) != std::string::npos) && 
stat(fileFullName.c_str(), &sb) == 0) {
-        uint64_t candidateModTime = ((uint64_t) (sb.st_mtime) * 1000);
-        if (candidateModTime >= file.currentTailFileModificationTime_) {
-          logging::LOG_TRACE(logger_) << "File " << filename << " (short name 
" << file.current_file_name_ <<
-          ") disk mod time " << candidateModTime << ", struct mod time " << 
file.currentTailFileModificationTime_ << ", size on disk " << sb.st_size << ", 
position " << file.currentTailFilePosition_;
-          if (filename == file.current_file_name_ && candidateModTime == 
file.currentTailFileModificationTime_ &&
-              sb.st_size == file.currentTailFilePosition_) {
-            return true;  // Skip the current file as a candidate in case it 
wasn't updated
-      }
-      TailMatchedFileItem item;
-      item.fileName = filename;
-      item.modifiedTime = ((uint64_t) (sb.st_mtime) * 1000);
-      matchedFiles.push_back(item);
-    }
-  }
-  return true;};
+std::vector<TailState> TailFile::findRotatedFiles(const TailState &state) 
const {
+  logger_->log_trace("Searching for files rolled over");
 
-    utils::file::FileUtils::list_dir(file.path_, lambda, logger_, false);
+  std::size_t last_dot_position = state.file_name_.find_last_of('.');
+  std::string base_name = state.file_name_.substr(0, last_dot_position);
+  std::string pattern = 
utils::file::PathUtils::replacePlaceholderWithBaseName(rolling_filename_pattern_,
 base_name);
 
-    if (matchedFiles.size() < 1) {
-      logger_->log_debug("No newer files found in directory!");
-      return;
+  std::vector<TailState> matched_files;
+  auto collect_matching_files = [&](const std::string &path, const std::string 
&file_name) -> bool {
+    if (file_name != state.file_name_ && 
utils::Regex::matchesFullInput(pattern, file_name)) {
+      std::string full_file_name = path + 
utils::file::FileUtils::get_separator() + file_name;
+      uint64_t mtime = utils::file::FileUtils::last_write_time(full_file_name);
+      if (mtime >= state.timestamp_ / 1000) {

Review comment:
       done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to