From: Perl 5 Porters Date: Tue, 18 Jun 1996 07:00:42 +0000 (+0000) Subject: Use newer File::Find to eliminate duplicate code X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dffa8cde9002476ae514bd0d995e9a1310014b8c;p=p5sagit%2Fp5-mst-13.2.git Use newer File::Find to eliminate duplicate code --- diff --git a/lib/find.pl b/lib/find.pl index 40e613e..29b83b0 100644 --- a/lib/find.pl +++ b/lib/find.pl @@ -29,80 +29,14 @@ # # Set the variable $dont_use_nlink if you're using AFS, since AFS cheats. -sub find { - chop($cwd = `pwd`); - foreach $topdir (@_) { - (($topdev,$topino,$topmode,$topnlink) = stat($topdir)) - || (warn("Can't stat $topdir: $!\n"), next); - if (-d _) { - if (chdir($topdir)) { - ($dir,$_) = ($topdir,'.'); - $name = $topdir; - &wanted; - ($fixtopdir = $topdir) =~ s,/$,, ; - &finddir($fixtopdir,$topnlink); - } - else { - warn "Can't cd to $topdir: $!\n"; - } - } - else { - unless (($dir,$_) = $topdir =~ m#^(.*/)(.*)$#) { - ($dir,$_) = ('.', $topdir); - } - $name = $topdir; - chdir $dir && &wanted; - } - chdir $cwd; - } -} - -sub finddir { - 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", return); - local(@filenames) = readdir(DIR); - closedir(DIR); +use File::Find (); - if ($nlink == 2 && !$dont_use_nlink) { # 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/$_"; - &wanted; - if ($subcount > 0 || $dont_use_nlink) { # Seen all the subdirs? +*name = *File::Find::name; +*prune = *File::Find::prune; +*dir = *File::Find::dir; - # 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 $_) { - &finddir($name,$nlink); - chdir '..'; - } - --$subcount; - } - } - } - } +sub find { + &File::Find::find(\&wanted, @_); } + 1; diff --git a/lib/finddepth.pl b/lib/finddepth.pl index 1fe6a37..5814a44 100644 --- a/lib/finddepth.pl +++ b/lib/finddepth.pl @@ -27,79 +27,15 @@ # ($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); - 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? +use File::Find (); - # Get link count and check for directoriness. +*name = *File::Find::name; +*prune = *File::Find::prune; +*dir = *File::Find::dir; - ($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;