Subject: | Missed root items for option depth enabled as iterator mode |
Date: | Thu, 22 Feb 2018 10:24:54 +0100 |
To: | bug-File-Find-Object-Rule [...] rt.cpan.org |
From: | Grzegorz Szyszlo <grzegorz.szyszlo [...] gmail.com> |
Environment:
Debian perl 5.20.2-3+deb8u9
Debian libfile-find-object-rule-perl 0.0305-1
perl -v
This is perl 5, version 20, subversion 2 (v5.20.2) built for
x86_64-linux-gnu-thread-multi
(with 100 registered patches, see perl -V for more detail)
additional info, linux distro debian/jessie , working directory is
formatted as XFS.
Example code that does not work as it should:
use File::Find::Object::Rule;
my $rule=File::Find::Object::Rule->new();
$rule->mindepth(1); #main directory should not be listed
$rule->extras({'depth'=>1}); #additional option for descending scan,
usable for remove tree
$rule->start('/full/path/to/destroy/something'); #make iterator
while (){
my $item = $rule->match(); #fetching iterator
last unless defined $item; #this should be done here, because
$item can be for example 0 or 00 or 000 file or directory, that is
defined as false and breaks while loop.
print "$item\n"; #it in some situation does not display first
level of subdirectories, because match() iterator does not give it.
#some optional work with destroying like:
#if (-d $item) {rmdir $item; next}; unlink $item; #destroy file or
directory
}
prepare on first level about 16 subdirectories, at second level 256
subdirectories perl first level subdirectory, and in all 2th level
subdirectory, prepare 256 empty files maked for example by touch shell
command.
Main directory contains only subdirectories, and its contains second
level of subdirectories. Finally, second level subdirectories contains
files.
Variant one, match method gives all items, excepts first subdirectory level.
Variant two, structure has only empty first subdirectory level, and all
is working properly.
I do some workaroud, continously call scanning with removing items,
unless last scan gives no elements. Usually it do 2 scans.