From: Gurusamy Sarathy Date: Wed, 1 Mar 2000 16:35:28 +0000 (+0000) Subject: fix minor compatibility issues with finddepth() (from Helmut Jarausch) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=579077630923d231795d873e06ff21d06d7753d9;p=p5sagit%2Fp5-mst-13.2.git fix minor compatibility issues with finddepth() (from Helmut Jarausch) p4raw-id: //depot/perl@5401 --- diff --git a/lib/File/Find.pm b/lib/File/Find.pm index a5e750e..0fa0032 100644 --- a/lib/File/Find.pm +++ b/lib/File/Find.pm @@ -520,8 +520,14 @@ sub _find_dir($$$) { $dir_pref = "$dir_name/"; if ( $nlink < 0 ) { # must be finddepth, report dirname now $name = $dir_name; + if ( substr($name,-2) eq '/.' ) { + $name =~ s|/\.$||; + } $dir = $p_dir; $_ = ($no_chdir ? $dir_name : $dir_rel ); + if ( substr($_,-2) eq '/.' ) { + s|/\.$||; + } &$wanted_callback; } else { push @Stack,[$CdLvl,$p_dir,$dir_rel,-1] if $bydepth; @@ -658,8 +664,15 @@ sub _find_dir_symlnk($$$) { } $fullname = $dir_loc; $name = $dir_name; + if ( substr($name,-2) eq '/.' ) { + $name =~ s|/\.$||; + } $dir = $p_dir; $_ = ($no_chdir ? $dir_name : $dir_rel); + if ( substr($_,-2) eq '/.' ) { + s|/\.$||; + } + &$wanted_callback; } else { push @Stack,[$dir_loc, $pdir_loc, $p_dir, $dir_rel,-1] if $bydepth; diff --git a/t/lib/filefind.t b/t/lib/filefind.t index 8e57aec..89999fd 100755 --- a/t/lib/filefind.t +++ b/t/lib/filefind.t @@ -9,8 +9,8 @@ BEGIN { unshift @INC, '../lib'; } -if ( $symlink_exists ) { print "1..59\n"; } -else { print "1..31\n"; } +if ( $symlink_exists ) { print "1..117\n"; } +else { print "1..61\n"; } use File::Find; @@ -29,6 +29,8 @@ END { rmdir 'fa'; rmdir 'fb/fba'; rmdir 'fb'; + chdir '..'; + rmdir 'for_find'; } sub Check($) { @@ -58,6 +60,31 @@ sub wanted { $File::Find::prune=1 if $_ eq 'faba'; } +sub dn_wanted { + my $n = $File::Find::name; + print "# '$n' => 1\n"; + my $i = rindex($n,'/'); + my $OK = exists($Expect{$n}); + if ( $OK ) { + $OK= exists($Expect{substr($n,0,$i)}) if $i >= 0; + } + Check($OK); + delete $Expect{$n}; +} + +sub d_wanted { + print "# '$_' => 1\n"; + my $i = rindex($_,'/'); + my $OK = exists($Expect{$_}); + if ( $OK ) { + $OK= exists($Expect{substr($_,0,$i)}) if $i >= 0; + } + Check($OK); + delete $Expect{$_}; +} + +MkDir( 'for_find',0770 ); +CheckDie(chdir(for_find)); MkDir( 'fa',0770 ); MkDir( 'fb',0770 ); touch('fb/fb_ord'); @@ -87,6 +114,22 @@ File::Find::find( {wanted => \&wanted, no_chdir => 1},'fa' ); Check( scalar(keys %Expect) == 0 ); +%Expect=('.' => 1, './fa' => 1, './fa/fsl' => 1, './fa/fa_ord' => 1, './fa/fab' => 1, + './fa/fab/fab_ord' => 1, './fa/fab/faba' => 1, + './fa/fab/faba/faba_ord' => 1, './fa/faa' => 1, './fa/faa/faa_ord' => 1, + './fb' => 1, './fb/fba' => 1, './fb/fba/fba_ord' => 1, './fb/fb_ord' => 1); +delete $Expect{'./fa/fsl'} unless $symlink_exists; +File::Find::finddepth( {wanted => \&dn_wanted },'.' ); +Check( scalar(keys %Expect) == 0 ); + +%Expect=('.' => 1, './fa' => 1, './fa/fsl' => 1, './fa/fa_ord' => 1, './fa/fab' => 1, + './fa/fab/fab_ord' => 1, './fa/fab/faba' => 1, + './fa/fab/faba/faba_ord' => 1, './fa/faa' => 1, './fa/faa/faa_ord' => 1, + './fb' => 1, './fb/fba' => 1, './fb/fba/fba_ord' => 1, './fb/fb_ord' => 1); +delete $Expect{'./fa/fsl'} unless $symlink_exists; +File::Find::finddepth( {wanted => \&d_wanted, no_chdir => 1 },'.' ); +Check( scalar(keys %Expect) == 0 ); + if ( $symlink_exists ) { %Expect=('.' => 1, 'fa_ord' => 1, 'fsl' => 1, 'fb_ord' => 1, 'fba' => 1, 'fba_ord' => 1, 'fab' => 1, 'fab_ord' => 1, 'faba' => 1, 'faa' => 1, @@ -94,12 +137,29 @@ if ( $symlink_exists ) { File::Find::find( {wanted => \&wanted, follow_fast => 1},'fa' ); Check( scalar(keys %Expect) == 0 ); + %Expect=('fa' => 1, 'fa/fa_ord' => 1, 'fa/fsl' => 1, 'fa/fsl/fb_ord' => 1, 'fa/fsl/fba' => 1, 'fa/fsl/fba/fba_ord' => 1, 'fa/fab' => 1, 'fa/fab/fab_ord' => 1, 'fa/fab/faba' => 1, 'fa/fab/faba/faba_ord' => 1, 'fa/faa' => 1, 'fa/faa/faa_ord' => 1); File::Find::find( {wanted => \&wanted, follow_fast => 1, no_chdir => 1},'fa' ); Check( scalar(keys %Expect) == 0 ); + + %Expect=('fa' => 1, 'fa/fa_ord' => 1, 'fa/fsl' => 1, 'fa/fsl/fb_ord' => 1, + 'fa/fsl/fba' => 1, 'fa/fsl/fba/fba_ord' => 1, 'fa/fab' => 1, + 'fa/fab/fab_ord' => 1, 'fa/fab/faba' => 1, 'fa/fab/faba/faba_ord' => 1, + 'fa/faa' => 1, 'fa/faa/faa_ord' => 1); + + File::Find::finddepth( {wanted => \&dn_wanted, follow_fast => 1},'fa' ); + Check( scalar(keys %Expect) == 0 ); + + %Expect=('fa' => 1, 'fa/fa_ord' => 1, 'fa/fsl' => 1, 'fa/fsl/fb_ord' => 1, + 'fa/fsl/fba' => 1, 'fa/fsl/fba/fba_ord' => 1, 'fa/fab' => 1, + 'fa/fab/fab_ord' => 1, 'fa/fab/faba' => 1, 'fa/fab/faba/faba_ord' => 1, + 'fa/faa' => 1, 'fa/faa/faa_ord' => 1); + + File::Find::finddepth( {wanted => \&d_wanted, follow_fast => 1, no_chdir => 1},'fa' ); + Check( scalar(keys %Expect) == 0 ); } print "# of cases: $case\n";