+warn "Legacy library @{[(caller(0))[6]]} will be removed from the Perl core distribution in the next major release. Please install it from the CPAN distribution Perl4::CoreLibs. It is being used at @{[(caller)[1]]}, line @{[(caller)[2]]}.\n";
+
+# 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.
+
# Usage:
# require "find.pl";
#
# 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.*$/ &&
# $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;