From: Mu-Woong Lee Date: Mon, 24 Apr 2017 10:39:36 +0000 (+0900) Subject: server: use the util::getFiles() helper instead of readdir_r() X-Git-Tag: accepted/tizen/unified/20170428.032554^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F126636%2F1;p=platform%2Fcore%2Fcontext%2Fcontext-store.git server: use the util::getFiles() helper instead of readdir_r() Change-Id: I40439c07fd5a775eb63ded93281d0357119bc6d9 Signed-off-by: Mu-Woong Lee --- diff --git a/src/server/SchemaLoader.cpp b/src/server/SchemaLoader.cpp index 252bcfa..0e513e4 100644 --- a/src/server/SchemaLoader.cpp +++ b/src/server/SchemaLoader.cpp @@ -16,10 +16,9 @@ #include #include +#include #include #include -#include -#include #include #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; }