From 195c58cd8b7251a45a5d005c721001bb1f70dd71 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 15 Feb 2016 19:48:57 -1000 Subject: [PATCH] ProjectPath DirectoryEnumerator integration --- hecl/extern/Athena | 2 +- hecl/extern/libBoo | 2 +- hecl/include/HECL/HECL.hpp | 5 +++ hecl/lib/ProjectPath.cpp | 66 +++++++++----------------------------- 4 files changed, 23 insertions(+), 52 deletions(-) diff --git a/hecl/extern/Athena b/hecl/extern/Athena index 8df75c8f2..ca0ff0434 160000 --- a/hecl/extern/Athena +++ b/hecl/extern/Athena @@ -1 +1 @@ -Subproject commit 8df75c8f23e32c38c7a9735fcc06538fbf412660 +Subproject commit ca0ff04340bd6a25eed1e738e6d976d4a10acf31 diff --git a/hecl/extern/libBoo b/hecl/extern/libBoo index 8ce4e6ffd..e9bd443e4 160000 --- a/hecl/extern/libBoo +++ b/hecl/extern/libBoo @@ -1 +1 @@ -Subproject commit 8ce4e6ffd32dc579bdbbad39abce1519251d7e37 +Subproject commit e9bd443e492478b7127ddce039c362f364792844 diff --git a/hecl/include/HECL/HECL.hpp b/hecl/include/HECL/HECL.hpp index 07f72cda0..d6fb0b0ef 100644 --- a/hecl/include/HECL/HECL.hpp +++ b/hecl/include/HECL/HECL.hpp @@ -1083,6 +1083,11 @@ public: */ void getDirChildren(std::map& outPaths) const; + /** + * @brief Construct DirectoryEnumerator set to project path + */ + HECL::DirectoryEnumerator enumerateDir() const; + /** * @brief Insert glob matches into existing vector * @param outPaths Vector to add matches to (will not erase existing contents) diff --git a/hecl/lib/ProjectPath.cpp b/hecl/lib/ProjectPath.cpp index d838cbca4..7606d468d 100644 --- a/hecl/lib/ProjectPath.cpp +++ b/hecl/lib/ProjectPath.cpp @@ -175,22 +175,15 @@ Time ProjectPath::getModtime() const } else if (S_ISDIR(theStat.st_mode)) { -#if _WIN32 -#else - DIR* dir = opendir(m_absPath.c_str()); - dirent* de; - while ((de = readdir(dir))) + HECL::DirectoryEnumerator de(m_absPath); + for (const HECL::DirectoryEnumerator::Entry& ent : de) { - if (de->d_name[0] == '.') - continue; - if (!HECL::Stat(de->d_name, &theStat)) + if (!HECL::Stat(ent.m_path.c_str(), &theStat)) { if (S_ISREG(theStat.st_mode) && theStat.st_mtime > latestTime) latestTime = theStat.st_mtime; } } - closedir(dir); -#endif return Time(latestTime); } } @@ -238,65 +231,38 @@ static void _recursiveGlob(Database::Project& proj, /* Compile component into regex */ SystemRegex regComp(comp, SystemRegex::ECMAScript); -#if _WIN32 -#else - DIR* dir = opendir(itStr.c_str()); - if (!dir) + HECL::DirectoryEnumerator de(itStr); + for (const HECL::DirectoryEnumerator::Entry& ent : de) { - LogModule.report(LogVisor::Error, "unable to open directory for traversal at '%s'", itStr.c_str()); - return; - } - - struct dirent* de; - while ((de = readdir(dir))) - { - if (std::regex_search(de->d_name, regComp)) + if (std::regex_search(ent.m_name, regComp)) { SystemString nextItStr = itStr; if (needSlash) nextItStr += '/'; - nextItStr += de->d_name; + nextItStr += ent.m_name; struct stat theStat; if (stat(nextItStr.c_str(), &theStat)) continue; - if (S_ISDIR(theStat.st_mode)) + if (ent.m_isDir) _recursiveGlob(proj, outPaths, level+1, pathCompMatches, nextItStr, true); - else if (S_ISREG(theStat.st_mode)) + else outPaths.emplace_back(proj, nextItStr); } } - - closedir(dir); -#endif } void ProjectPath::getDirChildren(std::map& outPaths) const { -#if _WIN32 -#else - struct dirent* de; - DIR* dir = opendir(m_absPath.c_str()); - if (!dir) - { - LogModule.report(LogVisor::Error, "unable to open directory for traversal at '%s'", m_absPath.c_str()); - return; - } + HECL::DirectoryEnumerator de(m_absPath); + for (const HECL::DirectoryEnumerator::Entry& ent : de) + outPaths[ent.m_name] = ProjectPath(*this, ent.m_name); +} - /* Add elements */ - rewinddir(dir); - while ((de = readdir(dir))) - { - if (!strcmp(de->d_name, ".")) - continue; - if (!strcmp(de->d_name, "..")) - continue; - outPaths[de->d_name] = ProjectPath(*this, de->d_name); - } - - closedir(dir); -#endif +HECL::DirectoryEnumerator ProjectPath::enumerateDir() const +{ + return HECL::DirectoryEnumerator(m_absPath); } void ProjectPath::getGlobResults(std::vector& outPaths) const