adamdebreceni commented on a change in pull request #1138:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1138#discussion_r679834067



##########
File path: libminifi/include/utils/file/FileUtils.h
##########
@@ -500,13 +500,26 @@ inline void addFilesMatchingExtension(const 
std::shared_ptr<logging::Logger> &lo
 #endif
 }
 
+inline std::string concat_path(const std::string& root, const std::string& 
child, bool force_posix = false) {
+  if (root.empty()) {
+    return child;
+  }
+  std::stringstream new_path;
+  if (root.back() == get_separator(force_posix)) {
+    new_path << root << child;
+  } else {
+    new_path << root << get_separator(force_posix) << child;
+  }
+  return new_path.str();
+}
+
 /*
  * Provides a platform-independent function to list a directory
  * Callback is called for every file found: first argument is the path of the 
directory, second is the filename
  * Return value of the callback is used to continue (true) or stop (false) 
listing
  */

Review comment:
       added

##########
File path: libminifi/test/unit/FileMatcherTests.cpp
##########
@@ -0,0 +1,208 @@
+/**
+ * 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.
+ */
+
+#define CUSTOM_EXTENSION_LIST
+
+#include "../TestBase.h"
+#include "../Path.h"
+#include "utils/file/FileMatcher.h"
+
+struct FileMatcherTestAccessor {
+  using FilePattern = fileutils::FileMatcher::FilePattern;
+};
+
+using FilePattern = FileMatcherTestAccessor::FilePattern;
+using FileMatcher = fileutils::FileMatcher;
+
+TEST_CASE("Invalid paths") {
+  REQUIRE_FALSE(FilePattern::fromPattern(""));
+  REQUIRE_FALSE(FilePattern::fromPattern("."));
+  REQUIRE_FALSE(FilePattern::fromPattern(".."));
+  REQUIRE_FALSE(FilePattern::fromPattern("!"));
+  REQUIRE_FALSE(FilePattern::fromPattern("!."));
+  REQUIRE_FALSE(FilePattern::fromPattern("!.."));
+}
+
+TEST_CASE("Matching directories without globs") {
+#ifdef WIN32
+  utils::Path root{"C:\\"};
+#else
+  utils::Path root{"/"};
+#endif
+  auto pattern = FilePattern::fromPattern((root / "one" / "banana" / 
"file").str()).value();
+  REQUIRE(pattern.match((root / "one").str()));
+  REQUIRE(pattern.match((root / "one" / "banana").str()));
+  REQUIRE_FALSE(pattern.match((root / "two").str()));
+  REQUIRE_FALSE(pattern.match((root / "one" / "apple").str()));
+  REQUIRE_FALSE(pattern.match((root / "one" / "banana" / "file").str()));

Review comment:
       added comment




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


Reply via email to