From 39401dac428722c409995462d5bd87155431c282 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Fri, 14 Sep 2018 11:22:44 -0400 Subject: [PATCH] don't use vendored director iterator --- llarp/fs.hpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/llarp/fs.hpp b/llarp/fs.hpp index cfd030a31..8935ede2c 100644 --- a/llarp/fs.hpp +++ b/llarp/fs.hpp @@ -22,6 +22,7 @@ namespace fs = std::experimental::filesystem; // openbsd needs this // linux gcc 7.2 needs this namespace fs = cpp17::filesystem; +#include #endif namespace llarp @@ -30,7 +31,7 @@ namespace llarp { typedef std::function< bool(const fs::path &) > PathVisitor; typedef std::function< void(const fs::path &, PathVisitor) > PathIter; -#if defined(CPP17) && defined(USE_CXX17_FILESYSTEM) +#if defined(USE_CXX17_FILESYSTEM) static PathIter IterDir = [](const fs::path &path, PathVisitor visit) { fs::directory_iterator i(path); auto itr = fs::begin(i); @@ -44,15 +45,21 @@ namespace llarp }; #else static PathIter IterDir = [](const fs::path &path, PathVisitor visit) { - fs::directory_iterator i(path); - auto itr = i.begin(); - while(itr != itr.end()) + DIR *d = opendir(path.c_str()); + if(d == nullptr) + return; + struct dirent *ent = nullptr; + do { - fs::path p = *itr; + ent = readdir(d); + if(!ent) + break; + fs::path p = path / fs::path(ent->d_name); + llarp::LogInfo(p); if(!visit(p)) - return; - ++itr; - } + break; + } while(ent); + closedir(d); }; #endif } // namespace util