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.
---