phrocker commented on a change in pull request #529: MINIFICPP-792 - TailFile 
processor should handle rotation of source file
URL: https://github.com/apache/nifi-minifi-cpp/pull/529#discussion_r270011728
 
 

 ##########
 File path: libminifi/src/processors/TailFile.cpp
 ##########
 @@ -179,58 +180,22 @@ void TailFile::checkRollOver(const std::string 
&fileLocation, const std::string
     std::size_t found = fileName.find_last_of(".");
     if (found != std::string::npos)
       pattern = fileName.substr(0, found);
-#ifndef WIN32
-    DIR *d;
-    d = opendir(fileLocation.c_str());
-    if (!d)
-      return;
-    while (1) {
-      struct dirent *entry;
-      entry = readdir(d);
-      if (!entry)
-        break;
-      std::string d_name = entry->d_name;
-      if (!(entry->d_type & DT_DIR)) {
-        std::string fileName = d_name;
-        std::string fileFullName = fileLocation + "/" + d_name;
-        if (fileFullName.find(pattern) != std::string::npos && 
stat(fileFullName.c_str(), &statbuf) == 0) {
-          if (((uint64_t) (statbuf.st_mtime) * 1000) >= 
modifiedTimeCurrentTailFile) {
-            TailMatchedFileItem item;
-            item.fileName = fileName;
-            item.modifiedTime = ((uint64_t) (statbuf.st_mtime) * 1000);
-            matchedFiles.push_back(item);
-          }
+
+    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) {
+        if (((uint64_t) (sb.st_mtime) * 1000) >= modifiedTimeCurrentTailFile) {
+          TailMatchedFileItem item;
+          item.fileName = filename;
+          item.modifiedTime = ((uint64_t) (sb.st_mtime) * 1000);
+          matchedFiles.push_back(item);
         }
       }
-    }
-    closedir(d);
-#else
-
-    HANDLE hFind;
-    WIN32_FIND_DATA FindFileData;
-
-    if ((hFind = FindFirstFile(fileLocation.c_str(), &FindFileData)) != 
INVALID_HANDLE_VALUE) {
-      do {
-        struct stat statbuf {};
-        if (stat(FindFileData.cFileName, &statbuf) != 0) {
-          logger_->log_warn("Failed to stat %s", FindFileData.cFileName);
-          break;
-        }
-
-        std::string fileFullName = fileLocation + "/" + FindFileData.cFileName;
+      return true;
+    };
 
-        if (fileFullName.find(pattern) != std::string::npos && 
stat(fileFullName.c_str(), &statbuf) == 0) {
-          if (((uint64_t)(statbuf.st_mtime) * 1000) >= 
modifiedTimeCurrentTailFile) {
-            TailMatchedFileItem item;
-            item.fileName = fileName;
-            item.modifiedTime = ((uint64_t)(statbuf.st_mtime) * 1000);
-            matchedFiles.push_back(item);
-          }
-        }
-      }while (FindNextFile(hFind, &FindFileData));
-      FindClose(hFind);
-    }
-#endif
+    utils::file::FileUtils::list_dir(fileLocation, lambda, logger_, false);
 
     // Sort the list based on modified time
     std::sort(matchedFiles.begin(), matchedFiles.end(), 
sortTailMatchedFileItem);
 
 Review comment:
   As per the java implementation if the times are the same we want to always 
we interrogate those rollovers properly, but i'm going to take a look a bit 
closer at this PR and run some tests.
   
   What tests did you perform to validate this? Did you have a TailFileTest for 
me to validate against?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to