X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Ffind.pl;h=ee5dc5d150654e9330b5aaeeeab089eb86291f79;hb=4f87fa576f174a31e6d8fdb08cae76e644395db0;hp=8dab0540f32786d1d16291ffd8da815c1939489a;hpb=8adcabd8d9cf3c71e660c45cb7165ae4694308d4;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/find.pl b/lib/find.pl index 8dab054..ee5dc5d 100644 --- a/lib/find.pl +++ b/lib/find.pl @@ -26,81 +26,22 @@ # $dev < 0 && # ($prune = 1); # } +# +# 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; - $topdir =~ s,/$,, ; - &finddir($topdir,$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); - - 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/$_"; - &wanted; - if ($subcount > 0) { # Seen all the subdirs? - - # Get link count and check for directoriness. - - ($dev,$ino,$mode,$nlink) = lstat($_) unless $nlink; - - if (-d _) { +use File::Find (); - # It really is a directory, so do it recursively. +*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; - if (!$prune && chdir $_) { - &finddir($name,$nlink); - chdir '..'; - } - --$subcount; - } - } - } - } +sub find { + &File::Find::find(\&wanted, @_); } + 1;