gulrak/filesystem

copy and remove_all with error_code throws

volcoma opened this issue · 4 comments

First of all - finally one working impl. Great job!

Describe the bug
copy and remove_all with error_code throws exceptions due to the error code not being propagated to the directory_iterator's constructor when iterating over the files.

        for (const directory_entry& x : directory_iterator(from)) {

    for (const directory_entry& de : directory_iterator(p)) {

shoud be

        for (const directory_entry& x : directory_iterator(from, ec)) {

    for (const directory_entry& de : directory_iterator(p, ec)) {

Expected behavior
These should not throw when using the error_code api

Thank you, for the kind words, and for the bug report. Indeed I missed those, and it hides two other issues. More test code to write...

Okay, I didn't run the tests on all my platforms yet (just fixed it from a macOS machine), but the fix is not complex, so I guess it will compile and work, and I will run tests on the other systems soon.
The next regular release v1.0.6 with the fix is scheduled for the upcomming weekend.

Actually even that fix is not enough. After more digging, another problem is actually using the error_code variant of directory_iterator in a range-based for loop, as it calls operator++ and that is not exception-free. Working on a fix. Need to use an explicit loop for guaranteed exception safety.

All tests look good.