Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File::Find behavior with files among @DIRS #9518

Closed
p5pRT opened this issue Oct 9, 2008 · 16 comments
Closed

File::Find behavior with files among @DIRS #9518

p5pRT opened this issue Oct 9, 2008 · 16 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 9, 2008

Migrated from rt.perl.org#59750 (status was 'resolved')

Searchable as RT59750$

@p5pRT
Copy link
Author

p5pRT commented Oct 9, 2008

From jflack@math.purdue.edu

Created by jflack@math.purdue.edu

This is a bug report for perl from jflack@​math.purdue.edu,
generated with the help of perlbug 1.35 running under perl v5.8.8.

-----------------------------------------------------------------
The File​::Find documentation never mentions any possibility of
including non-directories among @​DIRS, but it seems to be
possible and the resulting behavior seems to be about what one
would hope for​: preprocess and postprocess don't get called,
but wanted gets called with $File​::Find​::dir containing the
directory name and $_ containing the bare file name. This is
useful behavior (in the sense that if you wanted to write a
script that could accept a mix of file and directory arguments,
and File​::Find /didn't/ do this, you'd have to write a fairly
fiddly wrapper around File​::Find to accomplish the same thing).

So, unless there is a really strong objection to documenting the
current behavior (or on some platforms it actually won't work),
it would be nice to document it so people know it's available.

There is one small point where the behavior for a non-directory
in @​DIRS differs from the normal behavior​: $File​::Find​::dir
winds up with a terminal / where normally it does not. Nothing
the user can't work around with a File​::Spec->canonpath, but
it might be nice to make it consistent.

Perl Info

Flags:
    category=library
    severity=wishlist

Site configuration information for perl v5.8.8:

Configured by comand at Fri Oct  5 12:18:43 EDT 2007.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=solaris, osvers=2.8, archname=sun4-solaris-thread-multi
    uname='sunos ra 5.8 generic_117350-46 sun4u sparc sunw,sun-blade-1000'
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -xO3 -xarch=v8 -xspace -xildoff -I/opt/csw/bdb44/include -I/opt/csw/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-xO3 -xarch=v8 -xspace -xildoff',
    cppflags='-D_REENTRANT -xO3 -xarch=v8 -xspace -xildoff -I/opt/csw/bdb44/include -I/opt/csw/include'
    ccversion='Sun C 5.8 Patch 121015-04 2007/01/10', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-L/opt/csw/bdb44/lib -L/opt/csw/lib -L/usr/lib -L/usr/ccs/lib -L/opt/SUNWspro/prod/lib/v8plus -L/opt/SUNWspro/prod/lib -L/lib'
    libpth=/usr/lib /usr/ccs/lib /opt/SUNWspro/prod/lib/v8plus /opt/SUNWspro/prod/lib /lib /opt/csw/lib
    libs=-lsocket -lnsl -lgdbm -ldb-4.4 -ldl -lm -lpthread -lc
    perllibs=-lsocket -lnsl -ldb-4.4 -ldl -lm -lpthread -lc
    libc=/lib/libc.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-R /opt/csw/lib'
    cccdlflags='-KPIC', lddlflags='-G -L/opt/csw/bdb44/lib -L/opt/csw/lib -L/usr/lib -L/usr/ccs/lib -L/opt/SUNWspro/prod/lib/v8plus -L/opt/SUNWspro/prod/lib -L/lib'

Locally applied patches:
    


@INC for perl v5.8.8:
    /opt/csw/lib/perl/5.8.8
    /opt/csw/share/perl/5.8.8
    /opt/csw/lib/perl/site_perl
    /opt/csw/share/perl/site_perl
    /opt/csw/share/perl/site_perl
    /opt/csw/lib/perl/csw
    /opt/csw/share/perl/csw
    /opt/csw/share/perl/csw
    .


Environment for perl v5.8.8:
    HOME=/homes/jflack
    LANG=en_US.ISO8859-1
    LANGUAGE (unset)
    LC_COLLATE=en_US.ISO8859-1
    LC_CTYPE=en_US.ISO8859-1
    LC_MESSAGES=C
    LC_MONETARY=en_US.ISO8859-1
    LC_NUMERIC=en_US.ISO8859-1
    LC_TIME=en_US.ISO8859-1
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/opt/csw/bin:/local/bin:/local/sbin:/usr/xpg6/bin:/usr/xpg4/bin:/usr/bin:/sbin:/usr/sbin:/usr/openwin/bin:/usr/dt/bin:/pkgs/texlive/2005/bin/sparc-solaris:/usr/sfw/bin:/usr/local/bin:/opt/csw/bin:/opt/csw/sbin:/opt/csw/kde-gcc/bin
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh


@p5pRT
Copy link
Author

p5pRT commented Jan 13, 2012

From @jkeenan

On Thu Oct 09 08​:39​:46 2008, jflack@​math.purdue.edu wrote​:

The File​::Find documentation never mentions any possibility of
including non-directories among @​DIRS, but it seems to be
possible and the resulting behavior seems to be about what one
would hope for​: preprocess and postprocess don't get called,
but wanted gets called with $File​::Find​::dir containing the
directory name and $_ containing the bare file name. This is
useful behavior (in the sense that if you wanted to write a
script that could accept a mix of file and directory arguments,
and File​::Find /didn't/ do this, you'd have to write a fairly
fiddly wrapper around File​::Find to accomplish the same thing).

So, unless there is a really strong objection to documenting the
current behavior (or on some platforms it actually won't work),
it would be nice to document it so people know it's available.

There is one small point where the behavior for a non-directory
in @​DIRS differs from the normal behavior​: $File​::Find​::dir
winds up with a terminal / where normally it does not. Nothing
the user can't work around with a File​::Spec->canonpath, but
it might be nice to make it consistent.

If I am reading the File​::Find source code correctly, there is some
provision inside File​::Find​::_find_opt() for handling items passed to
the caller-level subroutines which are not, in fact, directories​:

#####
  462 sub _find_opt {
  463 my $wanted = shift;
...
  577 unless ($Is_Dir) {
  578 unless (($_,$dir) = File​::Basename​::fileparse($abs_dir)) {
  579 ($dir,$_) = ('./', $top_item);
  580 }
...
  620 }
#####

(I haven't studied the code between lines 577 and 620 well enough to say
what's happening.)

But the OP is correct with regard to the silence of the documentation on
the handling of non-directories. Do we need changes in the documentation?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Jan 13, 2012

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Mar 25, 2012

From @jkeenan

On Thu Jan 12 17​:24​:08 2012, jkeenan wrote​:

On Thu Oct 09 08​:39​:46 2008, jflack@​math.purdue.edu wrote​:

The File​::Find documentation never mentions any possibility of
including non-directories among @​DIRS, but it seems to be
possible and the resulting behavior seems to be about what one
would hope for​: preprocess and postprocess don't get called,
but wanted gets called with $File​::Find​::dir containing the
directory name and $_ containing the bare file name. This is
useful behavior (in the sense that if you wanted to write a
script that could accept a mix of file and directory arguments,
and File​::Find /didn't/ do this, you'd have to write a fairly
fiddly wrapper around File​::Find to accomplish the same thing).

So, unless there is a really strong objection to documenting the
current behavior (or on some platforms it actually won't work),
it would be nice to document it so people know it's available.

There is one small point where the behavior for a non-directory
in @​DIRS differs from the normal behavior​: $File​::Find​::dir
winds up with a terminal / where normally it does not. Nothing
the user can't work around with a File​::Spec->canonpath, but
it might be nice to make it consistent.

If I am reading the File​::Find source code correctly, there is some
provision inside File​::Find​::_find_opt() for handling items passed to
the caller-level subroutines which are not, in fact, directories​:

#####
462 sub _find_opt {
463 my $wanted = shift;
...
577 unless ($Is_Dir) {
578 unless (($_,$dir) = File​::Basename​::fileparse($abs_dir)) {
579 ($dir,$_) = ('./', $top_item);
580 }
...
620 }
#####

(I haven't studied the code between lines 577 and 620 well enough to say
what's happening.)

But the OP is correct with regard to the silence of the documentation on
the handling of non-directories. Do we need changes in the documentation?

Still need some feedback on this.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Apr 5, 2012

From @rjbs

As far as I'm concerned, this behavior can get documented as long as it's also got tests.

@p5pRT
Copy link
Author

p5pRT commented Apr 6, 2012

From @jkeenan

On Wed Apr 04 18​:42​:20 2012, rjbs wrote​:

As far as I'm concerned, this behavior can get documented as long as
it's also got tests.

Please review the patch attached.

Thank you very much.

Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Apr 6, 2012

From @jkeenan

0001-Individual-files-may-appear-in-list-of-directories-t.patch
From 83a5ca1bbe148630b3ed1fef4afe065377a79dd6 Mon Sep 17 00:00:00 2001
From: jkeenan <jkeenan@cpan.org>
Date: Thu, 5 Apr 2012 20:41:14 -0400
Subject: [PATCH] Individual files may appear in list of directories to be searched.

Document that, then demonstrate that with additional tests.

For RT #59750.
---
 lib/File/Find/t/find.t |   52 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 1 deletions(-)

diff --git a/lib/File/Find/t/find.t b/lib/File/Find/t/find.t
index 1d0a087..87306cc 100644
--- a/lib/File/Find/t/find.t
+++ b/lib/File/Find/t/find.t
@@ -18,7 +18,7 @@ BEGIN {
     $SIG{'__WARN__'} = sub { $warn_msg = $_[0]; warn "# $_[0]"; }
 }
 
-my $test_count = 85;
+my $test_count = 98;
 $test_count += 119 if $symlink_exists;
 $test_count += 26 if $^O eq 'MSWin32';
 $test_count += 2 if $^O eq 'MSWin32' and $symlink_exists;
@@ -108,6 +108,21 @@ sub cleanup {
 	rmdir dir_path('fb', 'fbc');
 	rmdir dir_path('fb');
     }
+    if (-d dir_path('fc')) {
+        unlink (
+            file_path('fc', 'fca', 'match_alpha'),
+            file_path('fc', 'fca', 'match_beta'),
+            file_path('fc', 'fcb', 'match_gamma'),
+            file_path('fc', 'fcb', 'delta'),
+            file_path('fc', 'fcc', 'match_epsilon'),
+            file_path('fc', 'fcc', 'match_zeta'),
+            file_path('fc', 'fcc', 'eta'),
+        );
+        rmdir dir_path('fc', 'fca');
+        rmdir dir_path('fc', 'fcb');
+        rmdir dir_path('fc', 'fcc');
+        rmdir dir_path('fc');
+    }
     if ($need_updir) {
         my $updir = $^O eq 'VMS' ? File::Spec::VMS->updir() : File::Spec->updir;
         chdir($updir);
@@ -870,6 +885,41 @@ if ($symlink_exists) {  # Issue 68260
     Check (!$dangling_symlink);
 }
 
+print "# RT 59750\n";
+MkDir( dir_path('fc'), 0770 );
+MkDir( dir_path('fc', 'fca'), 0770 );
+MkDir( dir_path('fc', 'fcb'), 0770 );
+MkDir( dir_path('fc', 'fcc'), 0770 );
+touch( file_path('fc', 'fca', 'match_alpha') );
+touch( file_path('fc', 'fca', 'match_beta') );
+touch( file_path('fc', 'fcb', 'match_gamma') );
+touch( file_path('fc', 'fcb', 'delta') );
+touch( file_path('fc', 'fcc', 'match_epsilon') );
+touch( file_path('fc', 'fcc', 'match_zeta') );
+touch( file_path('fc', 'fcc', 'eta') );
+
+my @files_from_mixed = ();
+sub wantmatch {
+    if ( $File::Find::name =~ m/match/ ) {
+        push @files_from_mixed, $_;
+        print "# \$_ => '$_'\n";
+    }
+}
+find( \&wantmatch, (
+    dir_path('fc', 'fca'),
+    dir_path('fc', 'fcb'),
+    dir_path('fc', 'fcc'),
+) );
+Check( scalar(@files_from_mixed) == 5 );
+
+@files_from_mixed = ();
+find( \&wantmatch, (
+    dir_path('fc', 'fca'),
+    dir_path('fc', 'fcb'),
+    file_path('fc', 'fcc', 'match_epsilon'),
+    file_path('fc', 'fcc', 'eta'),
+) );
+Check( scalar(@files_from_mixed) == 4 );
 
 if ($^O eq 'MSWin32') {
     # Check F:F:f correctly handles a root directory path.
-- 
1.6.3.2

@p5pRT
Copy link
Author

p5pRT commented Apr 6, 2012

From @jkeenan

On Thu Apr 05 17​:44​:35 2012, jkeenan wrote​:

On Wed Apr 04 18​:42​:20 2012, rjbs wrote​:

As far as I'm concerned, this behavior can get documented as long as
it's also got tests.

Please review the patch attached.

This patch didn't include the intended documentation change. I will try
to provide a new patch later today.

jimk

@p5pRT
Copy link
Author

p5pRT commented Apr 7, 2012

From @jkeenan

On Fri Apr 06 13​:31​:51 2012, jkeenan wrote​:

On Thu Apr 05 17​:44​:35 2012, jkeenan wrote​:

On Wed Apr 04 18​:42​:20 2012, rjbs wrote​:

As far as I'm concerned, this behavior can get documented as long as
it's also got tests.

Please review the patch attached.

This patch didn't include the intended documentation change. I will try
to provide a new patch later today.

jimk

@p5pRT
Copy link
Author

p5pRT commented Apr 7, 2012

From @jkeenan

0002-Individual-files-may-appear-in-list-of-directories-t.patch
From c07a361682707be2cd43004ce9eb572f4630691a Mon Sep 17 00:00:00 2001
From: jkeenan <jkeenan@cpan.org>
Date: Fri, 6 Apr 2012 20:20:59 -0400
Subject: [PATCH 2/2] Individual files may appear in list of directories to be searched.

Document that, then demonstrate that with additional tests.

For RT #59750.
---
 lib/File/Find.pm |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/lib/File/Find.pm b/lib/File/Find.pm
index f2fe20b..3b66d86 100644
--- a/lib/File/Find.pm
+++ b/lib/File/Find.pm
@@ -280,6 +280,14 @@ links that don't resolve:
          -l && !-e && print "bogus link: $File::Find::name\n";
     }
 
+Note that you may mix directories and (non-directory) files in the list of 
+directories to be searched by the C<wanted()>.
+
+    find(\&wanted, "./foo", "./bar", "./baz/epsilon");
+
+In the example above, no file in F<./baz/> other than F<./baz/epsilon> will be
+evaluated by C<wanted()>.
+
 See also the script C<pfind> on CPAN for a nice application of this
 module.
 
-- 
1.6.3.2

@p5pRT
Copy link
Author

p5pRT commented Apr 7, 2012

From @jkeenan

0001-Individual-files-may-appear-in-list-of-directories-t.patch
From 83a5ca1bbe148630b3ed1fef4afe065377a79dd6 Mon Sep 17 00:00:00 2001
From: jkeenan <jkeenan@cpan.org>
Date: Thu, 5 Apr 2012 20:41:14 -0400
Subject: [PATCH 1/2] Individual files may appear in list of directories to be searched.

Document that, then demonstrate that with additional tests.

For RT #59750.
---
 lib/File/Find/t/find.t |   52 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 1 deletions(-)

diff --git a/lib/File/Find/t/find.t b/lib/File/Find/t/find.t
index 1d0a087..87306cc 100644
--- a/lib/File/Find/t/find.t
+++ b/lib/File/Find/t/find.t
@@ -18,7 +18,7 @@ BEGIN {
     $SIG{'__WARN__'} = sub { $warn_msg = $_[0]; warn "# $_[0]"; }
 }
 
-my $test_count = 85;
+my $test_count = 98;
 $test_count += 119 if $symlink_exists;
 $test_count += 26 if $^O eq 'MSWin32';
 $test_count += 2 if $^O eq 'MSWin32' and $symlink_exists;
@@ -108,6 +108,21 @@ sub cleanup {
 	rmdir dir_path('fb', 'fbc');
 	rmdir dir_path('fb');
     }
+    if (-d dir_path('fc')) {
+        unlink (
+            file_path('fc', 'fca', 'match_alpha'),
+            file_path('fc', 'fca', 'match_beta'),
+            file_path('fc', 'fcb', 'match_gamma'),
+            file_path('fc', 'fcb', 'delta'),
+            file_path('fc', 'fcc', 'match_epsilon'),
+            file_path('fc', 'fcc', 'match_zeta'),
+            file_path('fc', 'fcc', 'eta'),
+        );
+        rmdir dir_path('fc', 'fca');
+        rmdir dir_path('fc', 'fcb');
+        rmdir dir_path('fc', 'fcc');
+        rmdir dir_path('fc');
+    }
     if ($need_updir) {
         my $updir = $^O eq 'VMS' ? File::Spec::VMS->updir() : File::Spec->updir;
         chdir($updir);
@@ -870,6 +885,41 @@ if ($symlink_exists) {  # Issue 68260
     Check (!$dangling_symlink);
 }
 
+print "# RT 59750\n";
+MkDir( dir_path('fc'), 0770 );
+MkDir( dir_path('fc', 'fca'), 0770 );
+MkDir( dir_path('fc', 'fcb'), 0770 );
+MkDir( dir_path('fc', 'fcc'), 0770 );
+touch( file_path('fc', 'fca', 'match_alpha') );
+touch( file_path('fc', 'fca', 'match_beta') );
+touch( file_path('fc', 'fcb', 'match_gamma') );
+touch( file_path('fc', 'fcb', 'delta') );
+touch( file_path('fc', 'fcc', 'match_epsilon') );
+touch( file_path('fc', 'fcc', 'match_zeta') );
+touch( file_path('fc', 'fcc', 'eta') );
+
+my @files_from_mixed = ();
+sub wantmatch {
+    if ( $File::Find::name =~ m/match/ ) {
+        push @files_from_mixed, $_;
+        print "# \$_ => '$_'\n";
+    }
+}
+find( \&wantmatch, (
+    dir_path('fc', 'fca'),
+    dir_path('fc', 'fcb'),
+    dir_path('fc', 'fcc'),
+) );
+Check( scalar(@files_from_mixed) == 5 );
+
+@files_from_mixed = ();
+find( \&wantmatch, (
+    dir_path('fc', 'fca'),
+    dir_path('fc', 'fcb'),
+    file_path('fc', 'fcc', 'match_epsilon'),
+    file_path('fc', 'fcc', 'eta'),
+) );
+Check( scalar(@files_from_mixed) == 4 );
 
 if ($^O eq 'MSWin32') {
     # Check F:F:f correctly handles a root directory path.
-- 
1.6.3.2

@p5pRT
Copy link
Author

p5pRT commented Apr 7, 2012

From @jkeenan

The two patches in the preceding post, if applied in order, should do
the trick. Please review.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Apr 25, 2012

From @cpansprout

On Fri Apr 06 17​:30​:01 2012, jkeenan wrote​:

The two patches in the preceding post, if applied in order, should do
the trick. Please review.

They are now waiting on the sprout/misc-post-5.16 to be merged after 5.16.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Apr 25, 2012

From [Unknown Contact. See original ticket]

On Fri Apr 06 17​:30​:01 2012, jkeenan wrote​:

The two patches in the preceding post, if applied in order, should do
the trick. Please review.

They are now waiting on the sprout/misc-post-5.16 to be merged after 5.16.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented May 22, 2012

From @cpansprout

On Tue Apr 24 17​:56​:38 2012, sprout wrote​:

On Fri Apr 06 17​:30​:01 2012, jkeenan wrote​:

The two patches in the preceding post, if applied in order, should do
the trick. Please review.

They are now waiting on the sprout/misc-post-5.16 to be merged after 5.16.

And have now been applied as 488985b and c82ae0b. Thakn yuo.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented May 22, 2012

@cpansprout - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant