bug in File::Find.pm?

John R. Comeau comeaujr at sd.conexant.com
Wed Mar 22 14:18:24 CST 2000


~sdpm~
While looking at Alan Stewart's "Browse and Grep" program (thanks
Alan), I think I may have found two bugs in File::Find.pm.

The first problem involves the $File::Find::prune variable.  The
documentation for Find.pm states that your 'wanted' subroutine can set
this variable to 1 to prevent Find.pm from recursing subdirectories.
However, I found that in the Find::finddir subroutine, $prune is
initalized to 0 before your 'wanted' subroutine is called.  The result
is that when you're searching 'by depth', the first subdirectory
located is searched even if you're setting $prune to 1 in wanted().
Perhaps it doesn't make any sense to search 'by depth' when you're
pruning?  I'd still expect Find.pm to work with that combination.

I've included a sample program (uuencoded below) to demonstrate this
problem.  I've also included my attempt at fixing these bugs, a new
Find.pm.  When my find.pl receives any command line argument, it uses
my version of Find.pm.  Otherwise it uses the standard one.  You'll
have to modify find.pl to push the location of my Find.pm into @INC if
you try out these examples.

My examples work with a directory structure as follows:

tmp (current directory for running find.pl)
  file_0.1
  dir1
     file_1.1
     file_1.2
  dir
     file_2.1
     file_2.2

This directory structure is also included in the uuencoded tar file below.

The behavior of problem 1 can be seen from running in the tmp directory
  find.pl

Here's an excerpt of the output:

  MYFIND 0, BY DEPTH 1, PRUNED 1
  wanted_prune: checking ./dir1/file_1.1  shouldn't be checked when pruning
  wanted_prune: checking ./dir1/file_1.2  shouldn't be checked when pruning
  wanted_prune: checking ./dir1
  wanted_prune: checking ./file_0.1
  wanted_prune: checking .

dir1 was recursed despite the fact that I'm setting $File::Find::prune
to 1 in my wanted_prune subroutine.

The second problem occurs when you're trying to prune but are not
searching 'by depth'.  In this case Find::find_opt () seems to
unecessarily check for $prune and won't even find the files in the
current directory if you set $File::Find::prune in your 'wanted'.
Here's output that demonstrates this behavior:

  MYFIND 0, BY DEPTH 0, PRUNED 1
  wanted_prune: checking .

The version of Find.pm that I found these problems in is the one which
came with perl 5.005_03.  According to www.perl.com, that's the latest
released version.

You can see the results using my version of Find.pm by running
  find.pl 1

The results follow:

  MYFIND 1, BY DEPTH 0, PRUNED 0
  wanted: checking .
  wanted: checking 
  wanted: checking ./dir1
  wanted: checking ./dir1/file_1.1
  wanted: checking ./dir1/file_1.2
  wanted: checking ./dir2
  wanted: checking ./dir2/file_2.1
  wanted: checking ./dir2/file_2.2
  wanted: checking ./file_0.1
   
  MYFIND 1, BY DEPTH 0, PRUNED 1
  wanted_prune: checking .
  wanted_prune: checking 
  wanted_prune: checking ./dir1
  wanted_prune: checking ./dir2
  wanted_prune: checking ./file_0.1
   
  MYFIND 1, BY DEPTH 1, PRUNED 0
  wanted: checking 
  wanted: checking ./dir1/file_1.1
  wanted: checking ./dir1/file_1.2
  wanted: checking ./dir1
  wanted: checking ./dir2/file_2.1
  wanted: checking ./dir2/file_2.2
  wanted: checking ./dir2
  wanted: checking ./file_0.1
  wanted: checking .
   
  MYFIND 1, BY DEPTH 1, PRUNED 1
  wanted_prune: checking 
  wanted_prune: checking ./file_0.1
  wanted_prune: checking .

One unfortunate side effect of my fixes is that the 'wanted'
subroutine is called once only for setting $File::Find::prune.  When
it's called at this time, $File::Find::name is undefined.  So any
'wanted' routine would have to check to see if $File::Find::name is
defined.  Hopefully I can fix this inconvenience, but I want to get
your feedback first.

-John

begin 644 find.tar.gz
M'XL("# GV3@  V9I;F0N=&%R .U:^7/:2!:>7]%?T7&H %DA#A^IPC;CC.U)
MO+4Y*L[,;*I<H00T1F,A,3I,F,3[M^_W7JM;"+ GV5HGNQ6ZD at CU\?H=WSNZ
ME60R;0R]J-7XX?Y:L[G3?+*[B^?>[DZSC6>SN=M^PL^L_=!\TMS;:[:VMW=:
MZ&_M-%OM'W;OD2?3TCAQ(VPY""?237^/;IL7N,-Z/(]OI4-2M'>V^;G=W+X7
M7N^A)=K^(\^7O9;3NH<]FBU8?F?G\^R_32IL[;9;&+\'7E;:QOX%^[?O88\O
MLK_R_XW]OU+;^/_&_AO__^[MW_Z?J?]VGZCZK[VI_[Y&,_9G_V]_^_B_NZ/\
MO[VS\?^OT);M_\WCO_+_W?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B&(TG77HWFB,DTR=[A75=6 at 0SFS13Q.^!IK0)2!L,_:R^RLX&SOX^U>L
M)L"C4F-&M8]E6R_YC>K&QFOZ=8[4-,.X76'7R]Z'85QX=R?>I;O4]^+\-R_8
M;@-O%@45/C\7+ at 0"=4%DY,BN""*<9>-$3A .^?!!QWL@$D0B20=9CDM!.NGC
M0(@ RJ=>(K9X">_2D1^=PRR68C&F%A=FJN. 9POI7#K,2MR8X,25R,")QZS\
M%WA]BY#8=MJ.9:+12O"T\AKV. Q&WN4M*E?!6$WI=-3S8Z4XKW*C( '[6)OS
M_U^=__M>T!CQIS__WKXQT?>_._[_7VN[U=+?_YI[[3W^_LOS[HVCA?:=?_][
M^*"1QE&##SX- @/=#=.'OUV+OHC1EZ(!0&L1%B=SOA3G>HRCYM'3-\]^K5G(
M?_D8%7QIP%@71V<OC^F+V1BZ;6@%\PX-W^M7V$V+9U?U[<VBT*%\Y(1A7VT*
MQQ$MWDJ/<3$QS(=*E(:SPO8B>/'NY[.7)YIG6_ST3IR<OG[[W-"TQ>LWO[P\
M/=&$LCQ-E*/!;]IG]2X_"OT%L*>*TH[I6+ at W.,D*6&:E]&CQPC*/.55#WQ;Z
M#H$J RHE;EUZVZJ\+. QTD^F M71434F>?OZ^]/"<B4;VW/M[?7^$G4U_ZX]
MMK)[KM4O0:C.)I\:SN/&IR73)>JC(=51?:E(PP#\&8.VPS9;7!7EMF8QOK4C
3;=JF;=JF_9^U?P, 3OIV #P  .JC
 
end
~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list