commit a38bbf551b4f49e47fe1da03b779edba66240d5f
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Oct 26 13:34:15 2016 +0100
Fix error handling in recursive_directory_iterator::increment
* src/filesystem/dir.cc (recursive_directory_iterator::increment):
Reset state on error.
* testsuite/experimental/filesystem/iterators/
recursive_directory_iterator.cc: Check state after increment error.
@@ -343,7 +343,10 @@ fs::recursive_directory_iterator::increment(error_code& ec) noexcept
{
_Dir dir = open_dir(top.entry.path(), _M_options, &ec);
if (ec)
- return *this;
+ {
+ _M_dirs.reset();
+ return *this;
+ }
if (dir.dirp)
_M_dirs->push(std::move(dir));
}
@@ -81,6 +81,7 @@ test01()
VERIFY( iter->path() == p/"d1/d2" );
iter.increment(ec); // should fail to recurse into p/d1/d2
VERIFY( ec );
+ VERIFY( iter == fs::recursive_directory_iterator() );
// Test inaccessible sub-directory, skipping permission denied.
iter = fs::recursive_directory_iterator(p, opts, ec);