Commits

Anonymous committed 4f49967

Fixed the check-for-link and for directory semantics on Windows

(and elsewhere).

- Fixed the check-for-link and for directory semantics on Windows
and other systems. Converted to "perldoc -f lstat" instead of
"perldoc -f stat", and using stat only for symbolic links to check
if they are directories. Now added a test for that.
- Fixed t/01ffo.t to check for the warning.
- Also see: http://www.nntp.perl.org/group/perl.perl5.porters/2009/01/msg143399.html

Comments (0)

Files changed (3)

+    - Fixed the check-for-link and for directory semantics on Windows
+    and other systems. Converted to "perldoc -f lstat" instead of 
+    "perldoc -f stat", and using stat only for symbolic links to check
+    if they are directories. Now added a test for that.
+        - Fixed t/01ffo.t to check for the warning.
+        - Also see: http://www.nntp.perl.org/group/perl.perl5.porters/2009/01/msg143399.html
+
 0.1.6 - Fri Jan  9 17:49:01 IST 2009
     - Converted the accessor generator to Class::XSAccessor instead
     of Class::Accessor. After consulting Devel::NYTProf, it seemed that

lib/File/Find/Object.pm

             item_obj
             _target_index
             _targets
+            _top_is_dir
+            _top_is_link
             _top_stat
             ), 
             @{__PACKAGE__->_get_options_ids()}
 
 =cut
 
-sub _curr_mode {
-    return shift->_top_stat->[2];
-}
-
 sub _curr_not_a_dir {
-    return !S_ISDIR( shift->_curr_mode() );
+    return !shift->_top_is_dir();
 }
 
 # Calculates _curr_path from $self->_curr_comps().
 sub _mystat {
     my $self = shift;
 
-    $self->_top_stat([stat($self->_curr_path())]);
+    $self->_top_stat([lstat($self->_curr_path())]);
+
+    $self->_top_is_dir(scalar(-d _));
+
+    if ($self->_top_is_link(scalar(-l _))) {
+        stat($self->_curr_path());
+        $self->_top_is_dir(scalar(-d _));
+    }
 
     return "SKIP";
 }
     # Don't pass strings directly to the format.
     # Instead - use %s
     # This was a security problem.
-    printf(STDERR
-        "Avoid loop %s => %s\n",
-            $ptr->_dir_as_string(),
-            $self->_curr_path()
-        );
+    warn(
+        sprintf(
+            "Avoid loop %s => %s\n",
+                $ptr->_dir_as_string(),
+                $self->_curr_path()
+        )
+    );
 
     return;
 }
 sub _non_top__check_subdir_helper {
     my $self = shift;
 
-    if (S_ISLNK($self->_curr_mode()) && !$self->followlink())
+    if ($self->_top_is_link() && !$self->followlink())
     {
         return 0;
     }
 
 use strict;
 use warnings;
-use Test::More tests => 3;
+use Test::More tests => 4;
 
+# TEST
 use_ok('File::Find::Object', "Can use main NBackup::Tree");
 
 mkdir('t/dir');
 eval {
     symlink('.', 't/dir/link');
 };
+my $symlink_created = ($@ eq "");
 
 my (@res1, @res2);
 my $tree = File::Find::Object->new(
     {
         callback => sub {
             push(@res1, $_[0]);
-        }
+        },
+        followlink => 1,
     },
     't/dir'
 );
 
+my @warnings;
+
+local $SIG{__WARN__} = sub { my $w = shift; push @warnings, $w; };
+
+# TEST
 ok($tree, "Can get tree object");
 
 while (my $r = $tree->next()) {
     push(@res2, $r);
 }
 
+# TEST
 ok(scalar(@res1) == scalar(@res2), "Get same result from callback and next");
+
+# TEST
+ok (
+    ($symlink_created ? scalar($warnings[0] =~ m{Avoid loop}) : 1),
+    "Avoid loop warning",
+);
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.