#include <cstdio>
#include <utility>
+#include <algorithm>
#include <fstream>
#include <sstream>
-#include <regex>
-#include <dirent.h>
#include <ServerUtil.h>
#include "DatabaseManager.h"
#include "Schema.h"
bool SchemaLoader::__loadSchemaDir(const std::string& dirPath)
{
- DIR* dir = NULL;
- struct dirent entry;
- struct dirent *result = NULL;
+ auto fileNames = util::getFiles(dirPath);
- dir = opendir(dirPath.c_str());
- IF_FAIL_RETURN_TAG(dir, false, _E, "Failed to open: %s", dirPath.c_str());
+ if (fileNames.empty())
+ return false;
- std::regex xmlFileRegex("^.*\\.(xml|XML)$", std::regex::optimize);
+ for (auto& name : fileNames) {
+ size_t pos = name.find_last_of('.');
- while (true) {
- if (readdir_r(dir, &entry, &result) != 0)
+ if (pos == std::string::npos)
continue;
- if (result == NULL)
- break;
-
- std::string filename = entry.d_name;
+ std::string extension = name.substr(pos);
+ std::transform(extension.begin(), extension.end(), extension.begin(), ::toupper);
- if (!std::regex_match(filename, xmlFileRegex))
+ if (extension != ".XML")
continue;
- __parseSchemaFile(dirPath + "/" + filename);
+ __parseSchemaFile(dirPath + "/" + name);
}
- closedir(dir);
return true;
}