Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
recursive_directory_iterator::increment does not advance on error #112
I'm using the latest develop branch (will be 1.71)
This is not (always?) true as the iterator does not advance when an error is reported during push_directory.
Steps to reproduce
Consider this program (slightly modified simple_ls.cpp from examples)
Now run the following commands (tested on linux):
I'm not sure what is better.
The first would have the disadvantage that because the iterator has already advances, the current path would not correspond to the error code, like this:
This is because testdir record is read and reported just fine, the error only happens once we try to recurse into that directory. So the contents are skipped and iterator now points to the next record in the parent directory.
The second variant, on the other hand, only works for errors connected to directory opens. What about other errors? Should another api be added to "acknowledge" the current error?
Many thanks for a wonderful library.
There is a third variant, which is very simple to fix and may be enough to break the loop:
The fix is very simple:
In my case, this will print the following output:
We can see that the record for testdir is printed twice: Once when the directory record is first discovered in the parent directory and once (with an error before it) when it is to be opened. I find it ok for these reasons:
The C++ standard mentions "Permission denied" error specifically here: http://eel.is/c++draft/fs.rec.dir.itr.members#23 It is configurable with an option, whether the directory we do not have access for should be silently skipped, or if an error should be raised.
If an error is to be raised, however, AFAIK the behaviour is unspecified whether the iterator should progress or not. I have only been able to find this general note: http://eel.is/c++draft/fs.err.report#3