Commits

Anonymous committed 79cc5fc

Allow File::Find::Object to properly accept paths to regular files as input
paths. Fixes:
- http://rt.cpan.org/Public/Bug/Display.html?id=33453
Thanks to Sergey V Panteleev for reporting the bug.

Also added a regression test for this behavior in t/03traverse.t.

  • Participants
  • Parent commits b119566

Comments (0)

Files changed (3)

     - Now running canonpath() on the targets in the call to 
-    File::Find::Object->new. That way, trailing slashes are omitted in
-    the results.
+      File::Find::Object->new. That way, trailing slashes are omitted in
+      the results.
+    - Allow File::Find::Object to properly accept paths to regular 
+      files as input paths. Fixes:
+        http://rt.cpan.org/Public/Bug/Display.html?id=33453
+      Thanks to Sergey V Panteleev for reporting the bug.
+    - TODO : check behavior on traversing non-existing paths.
 
 0.0.8 - Tue Jul 31 16:23:34 IDT 2007
     - added the empty PL_FILES key to the Makefile.PL to avoid running 

File lib/File/Find/Object.pm

 {
     my ($self, $current) = @_;
 
-    if ($self eq $current)
-    {
-        return 1;
-    }
+    # If current is not a directory always return 0, because we may
+    # be asked to traverse single-files.
     my @st = stat($self->_current_path($current));
     if (!-d _)
     {
         return 0;
     }
+
+    if ($self eq $current)
+    {
+        return 1;
+    }
     if (-l $self->_current_path($current) && !$self->followlink())
     {
         return 0;

File t/03traverse.t

 use strict;
 use warnings;
 
-use Test::More tests => 1;
+use Test::More tests => 2;
 
 BEGIN
 {
 
     rmtree($t->get_path("./t/sample-data/traverse-1"))
 }
+
+{
+    my $test_id = "traverse-dirs-and-files";
+    my $test_dir = "t/sample-data/$test_id";
+    my $tree =
+    {
+        'name' => "$test_id/",
+        'subs' =>
+        [   
+            {
+                'name' => "a/",
+                subs =>
+                [
+                    {
+                        'name' => "b.doc",
+                        'contents' => "This file was spotted in the wild.",
+                    },
+                ],
+            },
+            {
+                'name' => "foo/",
+                'subs' =>
+                [
+                    {
+                        'name' => "t.door.txt",
+                        'contents' => "A T Door",
+                    },
+                    {
+                        'name' => "yet/",
+                    },
+                ],
+            },
+        ],
+    };
+
+    my $t = File::Find::Object::TreeCreate->new();
+    $t->create_tree("./t/sample-data/", $tree);
+    my $ff = 
+        File::Find::Object->new(
+            {},
+            $t->get_path("./$test_dir/a/b.doc"),
+            $t->get_path("./$test_dir/foo"),
+        );
+    my @results;
+    for my $i (1 .. 5)
+    {
+        push @results, $ff->next();
+    }
+    # TEST
+    is_deeply(
+        \@results,
+        [(map { $t->get_path("$test_dir/$_") }
+            (qw(
+                a/b.doc
+                foo
+                foo/t.door.txt
+                foo/yet
+            ))),
+         undef
+        ],
+        "Checking that one can traverse regular files.",
+    );
+
+    rmtree($t->get_path("./$test_dir"))
+}