Introduce a new private method IntoIter::skip_current_dir_unless_contents_first
Make FilterEntry::next call skip_current_dir_unless_contents_first instead of skip_current_dir if the skipped entry is a directory
Add a test case that tests the combination of filter_entry and contents_first
Details
The documentation of IntoIter::filter_entry states that:
Note that if the iterator has contents_first enabled, then this method is no different than calling the standard Iterator::filter method (because directory entries are yielded after they’ve been descended into).
However, if contents_first was enabled and some directories were filtered out, unexpected entries may have been skipped regardless of the filter_entry results. Please refer to #171 for an example.
FilterEntry::next used to call skip_current_dir when the filtered out entry was a directory to stop reading the filtered out directory. skip_current_dir realizes this by popping the last DirList from stack_list. Unfortunately, if contents_first was enabled, skip_current_dir popped a wrong DirList from stack_list, because the DirList of the filtered out directory had already been removed from stack_list.
We should not update stack_list if contents_first is enabled. So I introduced skip_current_dir_unless_contents_first which does nothing if contents_first is enabled, otherwise calls skip_current_dir.
Proposed changes
IntoIter::skip_current_dir_unless_contents_first
FilterEntry::next
callskip_current_dir_unless_contents_first
instead ofskip_current_dir
if the skipped entry is a directoryfilter_entry
andcontents_first
Details
The documentation of
IntoIter::filter_entry
states that:However, if
contents_first
was enabled and some directories were filtered out, unexpected entries may have been skipped regardless of thefilter_entry
results. Please refer to #171 for an example.FilterEntry::next
used to callskip_current_dir
when the filtered out entry was a directory to stop reading the filtered out directory.skip_current_dir
realizes this by popping the lastDirList
fromstack_list
. Unfortunately, ifcontents_first
was enabled,skip_current_dir
popped a wrongDirList
fromstack_list
, because theDirList
of the filtered out directory had already been removed fromstack_list
.We should not update
stack_list
ifcontents_first
is enabled. So I introducedskip_current_dir_unless_contents_first
which does nothing ifcontents_first
is enabled, otherwise callsskip_current_dir
.