server: use the util::getFiles() helper instead of readdir_r() 36/126636/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 24 Apr 2017 10:39:36 +0000 (19:39 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 24 Apr 2017 10:39:36 +0000 (19:39 +0900)
Change-Id: I40439c07fd5a775eb63ded93281d0357119bc6d9
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/server/SchemaLoader.cpp

index 252bcfa..0e513e4 100644 (file)
 
 #include <cstdio>
 #include <utility>
+#include <algorithm>
 #include <fstream>
 #include <sstream>
-#include <regex>
-#include <dirent.h>
 #include <ServerUtil.h>
 #include "DatabaseManager.h"
 #include "Schema.h"
@@ -111,31 +110,26 @@ bool SchemaLoader::__createMetadataTables()
 
 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;
 }