Re: [ID 20011206.006] File::Find calls lstat on wrong object before wanted()
[p5sagit/p5-mst-13.2.git] / lib / File / Find.pm
index e64af10..3fbeebc 100644 (file)
@@ -209,15 +209,16 @@ warnings.
 =item $dont_use_nlink
 
 You can set the variable C<$File::Find::dont_use_nlink> to 1, if you want to
-force File::Find to always stat directories. This was used for systems
-that do not have the correct C<nlink> count for directories. Examples are
-ISO-9660 (CD-R), AFS, and operating systems like OS/2, DOS and a couple of
-others.
+force File::Find to always stat directories. This was used for file systems
+that do not have an C<nlink> count matching the number of sub-directories.
+Examples are ISO-9660 (CD-ROM), AFS, HPFS (OS/2 file system), FAT (DOS file
+system) and a couple of others.
 
-Since now File::Find should now detect such things on-the-fly and switch it
-self to using stat, this will probably not a problem to you.
+You shouldn't need to set this variable, since File::Find should now detect
+such file systems on-the-fly and switch itself to using stat. This works even
+for parts of your file system, like a mounted CD-ROM.
 
-If you do set $dont_use_nlink to 1, you will notice slow-downs.
+If you do set C<$File::Find::dont_use_nlink> to 1, you will notice slow-downs.
 
 =item symlinks
 
@@ -549,6 +550,8 @@ sub _find_opt {
                $cwd = "$cwd:" unless ($cwd =~ /:$/); # for safety
 
                if ($top_item eq $File::Find::current_dir) {
+                  # avoid empty name after return to '/'
+                  $name = '/' unless length( $name );
                    $abs_dir = $cwd;
                }
                else {
@@ -715,6 +718,8 @@ sub _find_dir($$$) {
            $_= ($no_chdir ? $dir_name : $dir_rel ); # $_
            # prune may happen here
            $prune= 0;
+            # guarantee lstat for directory
+            lstat( $dir_name );
            { &$wanted_callback };      # protect against wild "next"
            next if $prune;
        }
@@ -866,6 +871,8 @@ sub _find_dir($$$) {
                        s|/\.$||;
                    }
                }
+                # guarantee lstat at return to directory
+               lstat( $dir_name );
                { &$wanted_callback }; # protect against wild "next"
             }
             else {