This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #33892] Add Interix support
[perl5.git] / lib / File / Find.pm
index c81c02e..f2cecc1 100644 (file)
@@ -3,7 +3,7 @@ use 5.006;
 use strict;
 use warnings;
 use warnings::register;
-our $VERSION = '1.06';
+our $VERSION = '1.09';
 require Exporter;
 require Cwd;
 
@@ -126,7 +126,8 @@ C<wanted()> function is called. This enables fast file checks involving S< _>.
 =item *
 
 There is a variable C<$File::Find::fullname> which holds the absolute
-pathname of the file with all symbolic links resolved
+pathname of the file with all symbolic links resolved.  If the link is
+a dangling symbolic link, then fullname will be set to C<undef>.
 
 =back
 
@@ -591,7 +592,8 @@ sub _find_opt {
     local ($wanted_callback, $avoid_nlink, $bydepth, $no_chdir, $follow,
        $follow_skip, $full_check, $untaint, $untaint_skip, $untaint_pat,
        $pre_process, $post_process, $dangling_symlinks);
-    local($dir, $name, $fullname, $prune, $_);
+    local($dir, $name, $fullname, $prune);
+    local *_ = \my $a;
 
     my $cwd            = $wanted->{bydepth} ? Cwd::fastcwd() : Cwd::getcwd();
     my $cwd_untainted  = $cwd;
@@ -1100,7 +1102,21 @@ sub _find_dir_symlnk($$$) {
            $new_loc = Follow_SymLink($loc_pref.$FN);
 
            # ignore if invalid symlink
-           next unless defined $new_loc;
+            unless (defined $new_loc) {
+               if ($dangling_symlinks) {
+                   if (ref $dangling_symlinks eq 'CODE') {
+                       $dangling_symlinks->($FN, $dir_pref);
+                   } else {
+                       warnings::warnif "$dir_pref$FN is a dangling symbolic link\n";
+                   }
+               }
+
+               $fullname = undef;
+               $name = $dir_pref . $FN;
+               $_ = ($no_chdir ? $name : $FN);
+               { $wanted_callback->() };
+               next;
+           }
 
            if (-d _) {
                push @Stack,[$new_loc,$updir_loc,$dir_name,$FN,1];
@@ -1220,7 +1236,7 @@ $File::Find::current_dir = File::Spec->curdir || '.';
 
 $File::Find::dont_use_nlink = 1
     if $^O eq 'os2' || $^O eq 'dos' || $^O eq 'amigaos' || $^O eq 'MSWin32' ||
-       $^O eq 'cygwin' || $^O eq 'epoc' || $^O eq 'qnx' ||
+       $^O eq 'interix' || $^O eq 'cygwin' || $^O eq 'epoc' || $^O eq 'qnx' ||
           $^O eq 'nto';
 
 # Set dont_use_nlink in your hint file if your system's stat doesn't