Change 12582 by pudge@pudge-mobile on 2001/10/22 19:23:28 Sync with latest File::Find and tests from bleadperl.
Affected files ... ... //depot/maint-5.6/macperl/lib/File/Find.pm#6 edit ... //depot/maint-5.6/macperl/t/lib/filefind-taint.t#6 edit ... //depot/maint-5.6/macperl/t/lib/filefind.t#5 edit Differences ... ==== //depot/maint-5.6/macperl/lib/File/Find.pm#6 (text) ==== Index: perl/lib/File/Find.pm --- perl/lib/File/Find.pm.~1~ Mon Oct 22 13:30:06 2001 +++ perl/lib/File/Find.pm Mon Oct 22 13:30:06 2001 @@ -2,7 +2,7 @@ use 5.006; use strict; use warnings; -our $VERSION = '1.02'; +our $VERSION = '1.03'; require Exporter; require Cwd; @@ -180,9 +180,6 @@ filehandle that caches the information from the preceding stat(), lstat(), or filetest. -Set the variable C<$File::Find::dont_use_nlink> if you're using AFS, -since AFS cheats. - Here's another interesting wanted function. It will find all symbolic links that don't resolve: @@ -195,6 +192,23 @@ =head1 CAVEAT +=over 2 + +=item $dont_use_nlink + +You can set the variable C<$File::Find::dont_use_nlink> to 1, if you want to +force File::Find to always stat directories. This was used for systems +that do not have the correct C<nlink> count for directories. Examples are +ISO-9660 (CD-R), AFS, and operating systems like OS/2, DOS and a couple of +others. + +Since now File::Find should now detect such things on-the-fly and switch it +self to using stat, this will probably not a problem to you. + +If you do set $dont_use_nlink to 1, you will notice slow-downs. + +=item symlinks + Be aware that the option to follow symbolic links can be dangerous. Depending on the structure of the directory tree (including symbolic links to directories) you might traverse a given (physical) directory @@ -203,6 +217,8 @@ might cause very unpleasant surprises, since you delete or change files in an unknown directory. +=back + =head1 NOTES =over 4 @@ -643,6 +659,7 @@ my $dir_pref; my $dir_rel = $File::Find::current_dir; my $tainted = 0; + my $no_nlink; if ($Is_MacOS) { $dir_pref= ($p_dir =~ /:$/) ? $p_dir : "$p_dir:"; # preface @@ -736,7 +753,13 @@ @filenames = &$pre_process(@filenames) if $pre_process; push @Stack,[$CdLvl,$dir_name,"",-2] if $post_process; - if ($nlink == 2 && !$avoid_nlink) { + # default: use whatever was specifid + # (if $nlink >= 2, and $avoid_nlink == 0, this will switch back) + $no_nlink = $avoid_nlink; + # if dir has wrong nlink count, force switch to slower stat method + $no_nlink = 1 if ($nlink < 2); + + if ($nlink == 2 && !$no_nlink) { # This dir has no subdirectories. for my $FN (@filenames) { next if $FN =~ $File::Find::skip_pattern; @@ -753,7 +776,7 @@ for my $FN (@filenames) { next if $FN =~ $File::Find::skip_pattern; - if ($subcount > 0 || $avoid_nlink) { + if ($subcount > 0 || $no_nlink) { # Seen all the subdirs? # check for directoriness. # stat is faster for a file in the current directory ==== //depot/maint-5.6/macperl/t/lib/filefind-taint.t#6 (text) ==== Index: perl/t/lib/filefind-taint.t --- perl/t/lib/filefind-taint.t.~1~ Mon Oct 22 13:30:06 2001 +++ perl/t/lib/filefind-taint.t Mon Oct 22 13:30:06 2001 @@ -6,14 +6,19 @@ my %Expect_Dir = (); # what we expect for $File::Find::dir my ($cwd, $cwd_untainted); + BEGIN { chdir 't' if -d 't'; unshift @INC => '../lib'; +} - require Config; +use Config; - for (keys %ENV) { # untaint ENV - ($ENV{$_}) = $ENV{$_} =~ /(.*)/; +BEGIN { + if ($^O ne 'VMS') { + for (keys %ENV) { # untaint ENV + ($ENV{$_}) = $ENV{$_} =~ /(.*)/; + } } # Remove insecure directories from PATH @@ -138,28 +143,26 @@ # $File::Find::dir (%Expect_Dir). Also use it in file operations like # chdir, rmdir etc. # -# dir_path() concatenates directory names to form a _relative_ -# directory path, independant from the platform it's run on, although -# there are limitations. Don't try to create an absolute path, +# dir_path() concatenates directory names to form a *relative* +# directory path, independent from the platform it's run on, although +# there are limitations. Don't try to create an absolute path, # because that may fail on operating systems that have the concept of -# volume names (e.g. Mac OS). Be careful when you want to create an -# updir path like ../fa (Unix) or ::fa: (Mac OS). Plain directory -# names will work best. As a special case, you can pass it a "." as -# first argument, to create a directory path like "./fa/dir" on +# volume names (e.g. Mac OS). As a special case, you can pass it a "." +# as first argument, to create a directory path like "./fa/dir" on # operating systems other than Mac OS (actually, Mac OS will ignore # the ".", if it's the first argument). If there's no second argument, # this function will return the empty string on Mac OS and the string # "./" otherwise. sub dir_path { - my $first_item = shift @_; + my $first_arg = shift @_; - if ($first_item eq '.') { + if ($first_arg eq '.') { if ($^O eq 'MacOS') { return '' unless @_; # ignore first argument; return a relative path # with leading ":" and with trailing ":" - return File::Spec->catdir("", @_); + return File::Spec->catdir(@_); } else { # other OS return './' unless @_; my $path = File::Spec->catdir(@_); @@ -168,21 +171,16 @@ return $path; } - } else { # $first_item ne '.' - return $first_item unless @_; # return plain filename - if ($^O eq 'MacOS') { - # relative path with leading ":" and with trailing ":" - return File::Spec->catdir("", $first_item, @_); - } else { # other OS - return File::Spec->catdir($first_item, @_); - } + } else { # $first_arg ne '.' + return $first_arg unless @_; # return plain filename + return File::Spec->catdir($first_arg, @_); # relative path } } # Use topdir() to specify a directory path that you want to pass to -#find/finddepth Basically, topdir() does the same as dir_path() (see -#above), except that there's no trailing ":" on Mac OS. +# find/finddepth. Basically, topdir() does the same as dir_path() (see +# above), except that there's no trailing ":" on Mac OS. sub topdir { my $path = dir_path(@_); @@ -191,28 +189,28 @@ } -# Use file_path() to specify a file path that's expected for $_ (%Expect_File). -# Also suitable for file operations like unlink etc. - +# Use file_path() to specify a file path that's expected for $_ +# (%Expect_File). Also suitable for file operations like unlink etc. +# # file_path() concatenates directory names (if any) and a filename to -# form a _relative_ file path (the last argument is assumed to be a -# file). It's independant from the platform it's run on, although -# there are limitations (see the warnings for dir_path() above). As a -# special case, you can pass it a "." as first argument, to create a -# file path like "./fa/file" on operating systems other than Mac OS -# (actually, Mac OS will ignore the ".", if it's the first -# argument). If there's no second argument, this function will return -# the empty string on Mac OS and the string "./" otherwise. +# form a *relative* file path (the last argument is assumed to be a +# file). It's independent from the platform it's run on, although +# there are limitations. As a special case, you can pass it a "." as +# first argument, to create a file path like "./fa/file" on operating +# systems other than Mac OS (actually, Mac OS will ignore the ".", if +# it's the first argument). If there's no second argument, this +# function will return the empty string on Mac OS and the string "./" +# otherwise. sub file_path { - my $first_item = shift @_; + my $first_arg = shift @_; - if ($first_item eq '.') { + if ($first_arg eq '.') { if ($^O eq 'MacOS') { return '' unless @_; # ignore first argument; return a relative path # with leading ":", but without trailing ":" - return File::Spec->catfile("", @_); + return File::Spec->catfile(@_); } else { # other OS return './' unless @_; my $path = File::Spec->catfile(@_); @@ -221,14 +219,9 @@ return $path; } - } else { # $first_item ne '.' - return $first_item unless @_; # return plain filename - if ($^O eq 'MacOS') { - # relative path with leading ":", but without trailing ":" - return File::Spec->catfile("", $first_item, @_); - } else { # other OS - return File::Spec->catfile($first_item, @_); - } + } else { # $first_arg ne '.' + return $first_arg unless @_; # return plain filename + return File::Spec->catfile($first_arg, @_); # relative path } } ==== //depot/maint-5.6/macperl/t/lib/filefind.t#5 (xtext) ==== Index: perl/t/lib/filefind.t --- perl/t/lib/filefind.t.~1~ Mon Oct 22 13:30:06 2001 +++ perl/t/lib/filefind.t Mon Oct 22 13:30:06 2001 @@ -18,16 +18,19 @@ if ( $symlink_exists ) { print "1..188\n"; } else { print "1..78\n"; } -use File::Find; -use File::Spec; -if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'VMS') - { - # This is a hack - at present File::Find does not produce native names on - # Win32 or VMS, so force File::Spec to use Unix names. - require File::Spec::Unix; - @File::Spec::ISA = 'File::Spec::Unix'; - } - +BEGIN { + use File::Spec; + if ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'VMS') + { + # This is a hack - at present File::Find does not produce native names on + # Win32 or VMS, so force File::Spec to use Unix names. + # must be set *before* importing File::Find + require File::Spec::Unix; + @File::Spec::ISA = 'File::Spec::Unix'; + } + require File::Find; + import File::Find; +} cleanup(); find({wanted => sub { print "ok 1\n" if $_ eq 'if.t'; } }, @@ -168,28 +171,26 @@ # $File::Find::dir (%Expect_Dir). Also use it in file operations like # chdir, rmdir etc. # -# dir_path() concatenates directory names to form a _relative_ +# dir_path() concatenates directory names to form a *relative* # directory path, independent from the platform it's run on, although -# there are limitations. Don't try to create an absolute path, +# there are limitations. Don't try to create an absolute path, # because that may fail on operating systems that have the concept of -# volume names (e.g. Mac OS). Be careful when you want to create an -# updir path like ../fa (Unix) or ::fa: (Mac OS). Plain directory -# names will work best. As a special case, you can pass it a "." as -# first argument, to create a directory path like "./fa/dir" on +# volume names (e.g. Mac OS). As a special case, you can pass it a "." +# as first argument, to create a directory path like "./fa/dir" on # operating systems other than Mac OS (actually, Mac OS will ignore # the ".", if it's the first argument). If there's no second argument, # this function will return the empty string on Mac OS and the string # "./" otherwise. sub dir_path { - my $first_item = shift @_; + my $first_arg = shift @_; - if ($first_item eq '.') { + if ($first_arg eq '.') { if ($^O eq 'MacOS') { return '' unless @_; # ignore first argument; return a relative path # with leading ":" and with trailing ":" - return File::Spec->catdir("", @_); + return File::Spec->catdir(@_); } else { # other OS return './' unless @_; my $path = File::Spec->catdir(@_); @@ -198,21 +199,16 @@ return $path; } - } else { # $first_item ne '.' - return $first_item unless @_; # return plain filename - if ($^O eq 'MacOS') { - # relative path with leading ":" and with trailing ":" - return File::Spec->catdir("", $first_item, @_); - } else { # other OS - return File::Spec->catdir($first_item, @_); - } + } else { # $first_arg ne '.' + return $first_arg unless @_; # return plain filename + return File::Spec->catdir($first_arg, @_); # relative path } } # Use topdir() to specify a directory path that you want to pass to -#find/finddepth Basically, topdir() does the same as dir_path() (see -#above), except that there's no trailing ":" on Mac OS. +# find/finddepth. Basically, topdir() does the same as dir_path() (see +# above), except that there's no trailing ":" on Mac OS. sub topdir { my $path = dir_path(@_); @@ -222,27 +218,27 @@ # Use file_path() to specify a file path that's expected for $_ -# (%Expect_File). Also suitable for file operations like unlink etc. +# (%Expect_File). Also suitable for file operations like unlink etc. # # file_path() concatenates directory names (if any) and a filename to -# form a _relative_ file path (the last argument is assumed to be a +# form a *relative* file path (the last argument is assumed to be a # file). It's independent from the platform it's run on, although -# there are limitations (see the warnings for dir_path() above). As a -# special case, you can pass it a "." as first argument, to create a -# file path like "./fa/file" on operating systems other than Mac OS -# (actually, Mac OS will ignore the ".", if it's the first -# argument). If there's no second argument, this function will return -# the empty string on Mac OS and the string "./" otherwise. +# there are limitations. As a special case, you can pass it a "." as +# first argument, to create a file path like "./fa/file" on operating +# systems other than Mac OS (actually, Mac OS will ignore the ".", if +# it's the first argument). If there's no second argument, this +# function will return the empty string on Mac OS and the string "./" +# otherwise. sub file_path { - my $first_item = shift @_; + my $first_arg = shift @_; - if ($first_item eq '.') { + if ($first_arg eq '.') { if ($^O eq 'MacOS') { return '' unless @_; # ignore first argument; return a relative path # with leading ":", but without trailing ":" - return File::Spec->catfile("", @_); + return File::Spec->catfile(@_); } else { # other OS return './' unless @_; my $path = File::Spec->catfile(@_); @@ -251,14 +247,9 @@ return $path; } - } else { # $first_item ne '.' - return $first_item unless @_; # return plain filename - if ($^O eq 'MacOS') { - # relative path with leading ":", but without trailing ":" - return File::Spec->catfile("", $first_item, @_); - } else { # other OS - return File::Spec->catfile($first_item, @_); - } + } else { # $first_arg ne '.' + return $first_arg unless @_; # return plain filename + return File::Spec->catfile($first_arg, @_); # relative path } } End of Patch.