[ 
https://issues.apache.org/jira/browse/MINIFICPP-321?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16271542#comment-16271542
 ] 

ASF GitHub Bot commented on MINIFICPP-321:
------------------------------------------

Github user achristianson commented on a diff in the pull request:

    https://github.com/apache/nifi-minifi-cpp/pull/211#discussion_r153915241
  
    --- Diff: libminifi/src/processors/PutFile.cpp ---
    @@ -125,6 +135,29 @@ void PutFile::onTrigger(core::ProcessContext *context, 
core::ProcessSession *ses
       // If file exists, apply conflict resolution strategy
       struct stat statResult;
     
    +  if ((maxDestFiles != -1) && (stat(directory_.c_str(), &statResult) == 
0)) {
    +    // something exists at directory path
    +    if (S_ISDIR(statResult.st_mode)) {
    +      // it's a directory, count the files
    +      DIR *myDir = opendir(directory_.c_str());
    +      struct dirent* entry = nullptr;
    +
    +      int64_t ct = 0;
    +      while ((entry = readdir(myDir)) != nullptr) {
    +        if ((strcmp(entry->d_name, ".") != 0) && (strcmp(entry->d_name, 
"..") != 0)) {
    +          ct++;
    +          if (ct >= maxDestFiles) {
    +            logger_->log_warn("Routing to failure because the output 
directory %s has at least %u files, which exceeds the "
    +                "configured max number of files", directory_.c_str(), 
maxDestFiles);
    +            session->transfer(flowFile, Failure);
    +            return;
    +          }
    +        }
    +      }
    +      closedir(myDir);
    --- End diff --
    
    Would like to see either a RAII object to ensure open/close happens, or at 
least a try {} catch {} with the closedir call in all exception paths to ensure 
things are closed if there are exceptions.


> Support Maximum File Count in PutFile
> -------------------------------------
>
>                 Key: MINIFICPP-321
>                 URL: https://issues.apache.org/jira/browse/MINIFICPP-321
>             Project: NiFi MiNiFi C++
>          Issue Type: Improvement
>            Reporter: Dustin Rodrigues
>            Priority: Minor
>             Fix For: 0.4.0
>
>
> Support max file count that exists in Apache Nifi PutFile processor



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to