This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [PATCH] ID 20011206.007 File::Find:name set to empty string for "/"
authorWolfgang Laun <Wolfgang.Laun@alcatel.at>
Wed, 12 Dec 2001 10:52:21 +0000 (11:52 +0100)
committerJarkko Hietaniemi <jhi@iki.fi>
Wed, 12 Dec 2001 13:45:21 +0000 (13:45 +0000)
Message-ID: <200112121052210220.001ACE6B@smtp.chello.at>

p4raw-id: //depot/perl@13654

lib/File/Find.pm

index 3fbeebc..a0cfcb9 100644 (file)
@@ -150,7 +150,22 @@ C<$File::Find::dir> contains the current directory name, and C<$_> the
 current filename within that directory.  C<$File::Find::name> contains
 the complete pathname to the file. You are chdir()'d to
 C<$File::Find::dir> when the function is called, unless C<no_chdir>
-was specified.  When C<follow> or C<follow_fast> are in effect, there is
+was specified. Note that when changing to directories is in effect
+the root directory (F</>) is a somewhat special case inasmuch as the
+concatenation of C<$File::Find::dir>, C<'/'> and  C<$_> is not literally
+equal to C<$File::Find::name>. The table below summarizes all variants:
+
+              $File::Find::name  $File::Find::dir  $_
+ default      /                  /                 .
+ no_chdir=>0  /etc               /                 etc
+              /etc/x             /etc              x
+     
+ no_chdir=>1  /                  /                 /
+              /etc               /                 /etc
+              /etc/x             /etc              /etc/x
+
+
+When <follow> or <follow_fast> are in effect, there is
 also a C<$File::Find::fullname>.  The function may set
 C<$File::Find::prune> to prune the tree unless C<bydepth> was
 specified.  Unless C<follow> or C<follow_fast> is specified, for
@@ -863,12 +878,12 @@ sub _find_dir($$$) {
                }
                else {
                    if ( substr($name,-2) eq '/.' ) {
-                       $name =~ s|/\.$||;
+                       substr($name, length($name) == 2 ? -1 : -2) = '';
                    }
                    $dir = $p_dir;
                    $_ = ($no_chdir ? $dir_name : $dir_rel );
                    if ( substr($_,-2) eq '/.' ) {
-                       s|/\.$||;
+                       substr($_, length($_) == 2 ? -1 : -2) = '';
                    }
                }
                 # guarantee lstat at return to directory