szaszm commented on a change in pull request #1138: URL: https://github.com/apache/nifi-minifi-cpp/pull/1138#discussion_r694717942
########## File path: libminifi/include/utils/file/FileMatcher.h ########## @@ -0,0 +1,102 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <string> +#include <vector> +#include <set> +#include <utility> +#include <memory> + +#include "utils/OptionalUtils.h" +#include "core/logging/Logger.h" + +struct FileMatcherTestAccessor; + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace utils { +namespace file { + +class FileMatcher { Review comment: The implementation could still involve breaking up the code to different classes, I would just prefer the interface to be a function, just like `std::regex_match` is one. I think FilePattern is a better analogy to `std::regex`, although it doesn't involve expensive regex compilation in this case. What do you think about `utils::file::match(std::vector<FilePattern>)`? `forEachFile` could become a loop at the usage side instead. If the pattern is invalid, the FilePattern constructor could throw. If there are issues related to the filesystem, then the operation should throw. If a directory in a pattern doesn't exist, then that could be an empty match without failure, allowing us to load the rest of the extensions. There could be a function in ExtensionManager.cpp that converts the patterns string to a `vector<FilePattern>` and logs on error. ``` // ExtensionManager.cpp, anonymous namespace std::vector<FilePattern> splitPatterns(std::string_view patterns, core::logging::Logger& logger) { std::vector<FilePattern> result; const auto patterns_vector = StringUtils::split(patterns, ","); result.reserve(patterns_vector.size()); for (auto& pattern_str: patterns_vector) { auto pattern = FilePattern::fromPattern(pattern_str); // I would consider making this function a constructor // currently this returns an optional, but if it threw, this would become a try block if (pattern) result.push_back(*pattern); else logger->log_warn("Invalid pattern: %s", pattern_str); } result.shrink_to_fit(); return result; } // in ExtensionManager::initialize const auto files = utils::file::match(splitPatterns(*pattern, logger_)); ``` -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
