Skip Menu |

This queue is for tickets about the File-Find-Rule CPAN distribution.

Report information
The Basics
Id: 3133
Status: resolved
Priority: 0/
Queue: File-Find-Rule

People
Owner: RCLAMP [...] cpan.org
Requestors: tshinnic [...] io.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.11
Fixed in: (no value)



Subject: maxdepth/mindepth not what they seem (?)
[Well, shoot, I looked at 20_02 and you already have a comment about this. Ah well, maybe the below will give you some ideas] Started out wanting to compare files under a couple of directory trees to find duplicates. (yet another one of those...) During testing I figured the easiest way to limit runtime was to just say "don't descend more than a couple levels". So I used maxdepth(2). And it didn't return anything. >-O Played with it some more and found out that maxdepth() cared about all the directory component levels, including the levels Show quoted text
>>in the original starting paths<<. Ugh!
If I use two starting directories, oh say, c:/perl/lib and c:/perl/site/lib (smile if you will) then mindepth and maxdepth lose some (a lot?) of their usefulness because the starting paths have differing numbers of components. I'd kinda read the docs as meaning that the starting paths would be taken into account and it would be the _relative_ depths that would be tested. maxdepth( $level ) Descend at most $level (a non-negative integer) levels of directories below the starting point. Started wandering about and found $File::Find::topdir which the docs say is present (must be present?) for compatibility reasons. And without the follow options then this is the current starting path value. Using this we can derive our current partial path. After several iterations I've an example exec() routine. This basically does what you are doing, except first stripping off the starting path. I got rid of your special case lopping off the leading './' by using another File::Find variable. There is also the special case of examining the starting path itself. my $maxdepth = undef; $maxdepth = 2; my $mindepth = undef; # $mindepth = 3; $ffr->exec( sub { my( $fullpath, $topdir ) = ($File::Find::name, $File::Find::topdir); return 1 if length($topdir) >= length($fullpath); # could use if $topdir eq $fullpath; instead my $partpath = substr( $fullpath, length($topdir)+1); my $partdepth = scalar File::Spec->splitdir($partpath); $File::Find::prune = 1 if defined $maxdepth && $partdepth > $maxdepth; return if defined $mindepth && $partdepth <= $mindepth; 1; } );
[guest - Sun Aug 3 09:23:52 2003]: Show quoted text
> [Well, shoot, I looked at 20_02 and you already have a comment about > this. Ah well, maybe the below will give you some ideas] >
It was very useful, both in terms of pointing me at the ::topdir variable and in prodding me into actually fixing it this time rather than just noting the bug. Thanks. Though I've not yet worked up a thorough test for this, if you could grab 0.20_03 from CPAN and let me know if it works for you I'd appreciate it. -- Richard Clamp <richardc@unixbeard.net>
[RCLAMP - Mon Aug 4 05:52:09 2003]: Show quoted text
> Though I've not yet worked up a thorough test for this, if you could > grab 0.20_03 from CPAN and let me know if it works for you I'd > appreciate it.
0.20 Was released to the CPAN today, which I believe addresses this issue. -- Richard Clamp <richardc@unixbeard.net>