* Foundation. See file COPYING.
*/
+#include "PyModuleRegistry.h"
+
+#if __has_include(<filesystem>)
+#include <filesystem>
+namespace fs = std::filesystem;
+#elif __has_include(<experimental/filesystem>)
+#include <experimental/filesystem>
+namespace fs = std::experimental::filesystem;
+#else
+#error std::filesystem not available!
+#endif
#include "include/stringify.h"
#include "common/errno.h"
#include "ActivePyModules.h"
-#include "PyModuleRegistry.h"
-
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_mgr
std::set<std::string> PyModuleRegistry::probe_modules(const std::string &path) const
{
- DIR *dir = opendir(path.c_str());
- if (!dir) {
- return {};
- }
-
- std::set<std::string> modules_out;
- struct dirent *entry = NULL;
- while ((entry = readdir(dir)) != NULL) {
- string n(entry->d_name);
- string fn = path + "/" + n;
- struct stat st;
- int r = ::stat(fn.c_str(), &st);
- if (r == 0 && S_ISDIR(st.st_mode)) {
- string initfn = fn + "/module.py";
- r = ::stat(initfn.c_str(), &st);
- if (r == 0) {
- modules_out.insert(n);
- }
+ std::set<std::string> modules;
+ for (const auto& entry: fs::directory_iterator(path)) {
+ if (!fs::is_directory(entry)) {
+ continue;
+ }
+ auto module_path = entry.path() / "module.py";
+ if (fs::exists(module_path)) {
+ modules.emplace(entry.path().filename());
}
}
- closedir(dir);
-
- return modules_out;
+ return modules;
}
int PyModuleRegistry::handle_command(