Skip to content

Commit

Permalink
refs #68, better permission error handling for directory_iteratior wi…
Browse files Browse the repository at this point in the history
…th skip_permissions_denied
  • Loading branch information
gulrak committed Aug 20, 2020
1 parent 3f1c185 commit 2ea0017
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5195,13 +5195,19 @@ class directory_iterator::impl
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);
Expand All @@ -5212,7 +5218,7 @@ class directory_iterator::impl
}
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;
Expand Down

0 comments on commit 2ea0017

Please sign in to comment.