X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Ffinddepth.pl;h=6a177c6113fae3372f9524bd9c0bdfb1907c11c0;hb=6182169b72782336c6202161aa4cde16ac88296e;hp=1fe6a375b6c9ff7a4d49a56cede33352b77b9b25;hpb=a0d0e21ea6ea90a22318550944fe6cb09ae10cda;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/finddepth.pl b/lib/finddepth.pl index 1fe6a37..6a177c6 100644 --- a/lib/finddepth.pl +++ b/lib/finddepth.pl @@ -1,3 +1,12 @@ +# This library is deprecated and unmaintained. It is included for +# compatibility with Perl 4 scripts which may use it, but it will be +# removed in a future version of Perl. Please use the File::Find module +# instead. + +warn( "Please use the File::Find module instead of the deprecated" + ." 'finddepth.pl' library, which will be removed in the next" + ." major release of perl" ); + # Usage: # require "finddepth.pl"; # @@ -10,11 +19,11 @@ # to $dir when the function is called. The function may # set $prune to prune the tree. # -# This library is primarily for find2perl, which, when fed +# For example, # -# find2perl / -name .nfs\* -mtime +7 -exec rm -f {} \; -o -fstype nfs -prune +# find / -name .nfs\* -mtime +7 -exec rm -f {} \; -o -fstype nfs -prune # -# spits out something like this +# corresponds to this # # sub wanted { # /^\.nfs.*$/ && @@ -27,79 +36,20 @@ # ($prune = 1); # } -sub finddepth { - chop($cwd = `pwd`); - foreach $topdir (@_) { - (($topdev,$topino,$topmode,$topnlink) = stat($topdir)) - || (warn("Can't stat $topdir: $!\n"), next); - if (-d _) { - if (chdir($topdir)) { - ($fixtopdir = $topdir) =~ s,/$,, ; - &finddepthdir($fixtopdir,$topnlink); - ($dir,$_) = ($fixtopdir,'.'); - $name = $fixtopdir; - &wanted; - } - else { - warn "Can't cd to $topdir: $!\n"; - } - } - else { - unless (($dir,$_) = $topdir =~ m#^(.*/)(.*)$#) { - ($dir,$_) = ('.', $topdir); - } - chdir $dir && &wanted; - } - chdir $cwd; - } -} - -sub finddepthdir { - local($dir,$nlink) = @_; - local($dev,$ino,$mode,$subcount); - local($name); - - # Get the list of files in the current directory. - opendir(DIR,'.') || warn "Can't open $dir: $!\n"; - local(@filenames) = readdir(DIR); - closedir(DIR); +use File::Find (); - if ($nlink == 2) { # This dir has no subdirectories. - for (@filenames) { - next if $_ eq '.'; - next if $_ eq '..'; - $name = "$dir/$_"; - $nlink = 0; - &wanted; - } - } - else { # This dir has subdirectories. - $subcount = $nlink - 2; - for (@filenames) { - next if $_ eq '.'; - next if $_ eq '..'; - $nlink = $prune = 0; - $name = "$dir/$_"; - if ($subcount > 0) { # Seen all the subdirs? +*name = *File::Find::name; +*prune = *File::Find::prune; +*dir = *File::Find::dir; +*topdir = *File::Find::topdir; +*topdev = *File::Find::topdev; +*topino = *File::Find::topino; +*topmode = *File::Find::topmode; +*topnlink = *File::Find::topnlink; - # Get link count and check for directoriness. - - ($dev,$ino,$mode,$nlink) = lstat($_) unless $nlink; - - if (-d _) { - - # It really is a directory, so do it recursively. - - if (!$prune && chdir $_) { - &finddepthdir($name,$nlink); - chdir '..'; - } - --$subcount; - } - } - &wanted; - } - } +sub finddepth { + &File::Find::finddepth(\&wanted, @_); } + 1;