entity-manager: Search sysconfdir for configurations

Make it easier to iteratively develop configurations in-place with a
read-only /usr.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Id0853b579a61394cb2b6ef0a3858ba01e5cb2893
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 48c600a..489d47a 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -34,6 +34,7 @@
 
 #include <filesystem>
 #include <fstream>
+#include <map>
 #include <regex>
 
 constexpr const char* templateChar = "$";
@@ -63,6 +64,36 @@
     return true;
 }
 
+bool findFiles(const std::vector<fs::path>&& dirPaths,
+               const std::string& matchString,
+               std::vector<fs::path>& foundPaths)
+{
+    std::map<fs::path, fs::path> paths;
+    std::regex search(matchString);
+    std::smatch match;
+    for (const auto& dirPath : dirPaths)
+    {
+        if (!fs::exists(dirPath))
+            continue;
+
+        for (const auto& p : fs::directory_iterator(dirPath))
+        {
+            std::string path = p.path().string();
+            if (std::regex_search(path, match, search))
+            {
+                paths[p.path().filename()] = p.path();
+            }
+        }
+    }
+
+    for (const auto& [key, value] : paths)
+    {
+        foundPaths.emplace_back(value);
+    }
+
+    return !foundPaths.empty();
+}
+
 bool getI2cDevicePaths(const fs::path& dirPath,
                        boost::container::flat_map<size_t, fs::path>& busPaths)
 {