From 2ea00170e1d0ff4903abee13cfbba26e42d7bd2d Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Thu, 20 Aug 2020 21:58:34 +0200 Subject: [PATCH] refs #68, better permission error handling for directory_iteratior with skip_permissions_denied --- include/ghc/filesystem.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 5cd76ae..477447c 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -5195,13 +5195,19 @@ public: void increment(std::error_code& ec) { if (_dir) { + bool skip; do { + skip = false; errno = 0; - _entry = readdir(_dir); + _entry = ::readdir(_dir); if (_entry) { _current = _base; _current.append_name(_entry->d_name); _dir_entry = directory_entry(_current, ec); + if(ec && (ec.value() == EACCES || ec.value() == EPERM) && (_options & directory_options::skip_permission_denied) == directory_options::skip_permission_denied) { + ec.clear(); + skip = true; + } } else { ::closedir(_dir); @@ -5212,7 +5218,7 @@ public: } break; } - } while (std::strcmp(_entry->d_name, ".") == 0 || std::strcmp(_entry->d_name, "..") == 0); + } while (skip || std::strcmp(_entry->d_name, ".") == 0 || std::strcmp(_entry->d_name, "..") == 0); } } path _base;