From 9b7860125d2328176e40e63670efe1a1338ad905 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sat, 11 Mar 2023 02:01:50 -0800 Subject: [PATCH] ensure elements in deepest dir are added to output list --- library/modules/Filesystem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/modules/Filesystem.cpp b/library/modules/Filesystem.cpp index a182ac062..2c275ceba 100644 --- a/library/modules/Filesystem.cpp +++ b/library/modules/Filesystem.cpp @@ -255,13 +255,14 @@ static int listdir_recursive_impl (std::string prefix, std::string path, std::string path_file = path + *file; if (Filesystem::isdir(prefixed_file)) { + files.insert(std::pair(include_prefix ? prefixed_file : path_file, true)); + if (depth == 0) { out_of_depth = true; continue; } - files.insert(std::pair(include_prefix ? prefixed_file : path_file, true)); err = listdir_recursive_impl(prefix, path_file + "/", files, depth - 1, include_prefix); if (err) return err; @@ -277,5 +278,7 @@ static int listdir_recursive_impl (std::string prefix, std::string path, int Filesystem::listdir_recursive (std::string dir, std::map &files, int depth /* = 10 */, bool include_prefix /* = true */) { + if (dir.size() && dir[dir.size()-1] == '/') + dir.resize(dir.size()-1); return listdir_recursive_impl(dir, "", files, depth, include_prefix); }