This is an automated email from the ASF dual-hosted git repository.

lordgamez pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit e31ee031bf43fb220ea62b7b6b4f09f45f09668d
Author: Adam Debreceni <[email protected]>
AuthorDate: Mon Aug 15 11:28:30 2022 +0200

    MINIFICPP-1905 - Enumerate only relevant subdir contents
    
    Signed-off-by: Gabor Gyimesi <[email protected]>
    
    This closes #1386
---
 libminifi/include/utils/file/FileUtils.h | 21 +++++---------------
 libminifi/test/unit/FilePatternTests.cpp | 33 ++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/libminifi/include/utils/file/FileUtils.h 
b/libminifi/include/utils/file/FileUtils.h
index 6ba8a3654..92a6884b2 100644
--- a/libminifi/include/utils/file/FileUtils.h
+++ b/libminifi/include/utils/file/FileUtils.h
@@ -14,8 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef LIBMINIFI_INCLUDE_UTILS_FILE_FILEUTILS_H_
-#define LIBMINIFI_INCLUDE_UTILS_FILE_FILEUTILS_H_
+
+#pragma once
 
 #include <filesystem>
 #include <fstream>
@@ -80,12 +80,7 @@
 #endif
 
 
-namespace org {
-namespace apache {
-namespace nifi {
-namespace minifi {
-namespace utils {
-namespace file {
+namespace org::apache::nifi::minifi::utils::file {
 
 namespace FileUtils = ::org::apache::nifi::minifi::utils::file;
 
@@ -373,7 +368,7 @@ inline void list_dir(const std::string& dir,
     std::string path = entry.path().string();
 
     if (utils::file::is_directory(path)) {  // if this is a directory
-      if (dir_callback(dir)) {
+      if (dir_callback(path)) {
         list_dir(path, callback, logger, dir_callback);
       }
     } else {
@@ -756,10 +751,4 @@ inline std::optional<std::string> get_relative_path(const 
std::string& path, con
   return std::filesystem::relative(path, base_path).string();
 }
 
-}  // namespace file
-}  // namespace utils
-}  // namespace minifi
-}  // namespace nifi
-}  // namespace apache
-}  // namespace org
-#endif  // LIBMINIFI_INCLUDE_UTILS_FILE_FILEUTILS_H_
+}  // namespace org::apache::nifi::minifi::utils::file
diff --git a/libminifi/test/unit/FilePatternTests.cpp 
b/libminifi/test/unit/FilePatternTests.cpp
index 7ce45cb19..e0c9fd70c 100644
--- a/libminifi/test/unit/FilePatternTests.cpp
+++ b/libminifi/test/unit/FilePatternTests.cpp
@@ -250,3 +250,36 @@ TEST_CASE("Excluding with directory wildcard exclusion") {
   REQUIRE_NOT_MATCHING(pattern.match(root / "one" / "six/"));
   REQUIRE_EXCLUDE(pattern.match(root / "one" / "ten" / "file.txt"));
 }
+
+TEST_CASE("Check only relevant subdir contents") {
+  TestController controller;
+  std::filesystem::path root{controller.createTempDirectory()};
+  // root
+  //   |- file1.txt
+  //   |- one
+  //   |   |- file2.txt
+  //   |
+  //   |- two
+  //       |- file3.txt
+  minifi::utils::file::create_dir((root / "one").string(), true);
+  minifi::utils::file::create_dir((root / "two").string(), true);
+
+  auto file1 = root / "file1.txt";
+  auto file2 = root / "one" / "file2.txt";
+  auto file3 = root / "two" / "file3.txt";
+
+  for (const auto& file : {file1, file2, file3}) {std::ofstream{file};}
+
+  std::set<std::filesystem::path> checked_files;
+  auto file_cb = [&] (const std::string& dir, const std::string& file) -> bool 
{
+    checked_files.insert(utils::file::concat_path(dir, file));
+    return true;
+  };
+  auto dir_cb = [&] (const std::string& dir) -> bool {
+    // only check the "one" subdir
+    return std::filesystem::path{dir} == root / "one";
+  };
+  utils::file::list_dir(root.string(), file_cb, controller.getLogger(), 
dir_cb);
+
+  REQUIRE((checked_files == std::set<std::filesystem::path>{file1, file2}));
+}

Reply via email to