develooper Front page | perl.perl5.porters | Postings from May 2003

[perl #22195] File::Find, sorted directory traversal order is inverted

Thread Previous
From:
perlbug-followup
Date:
May 13, 2003 22:16
Subject:
[perl #22195] File::Find, sorted directory traversal order is inverted
Message ID:
rt-22195-57562.8.45250322464338@bugs6.perl.org
# New Ticket Created by  anthony@griffith.edu.au 
# Please include the string:  [perl #22195]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=22195 >



This is a bug report for perl from anthony@cit.gu.edu.au,
generated with the help of perlbug 1.34 running under perl v5.8.0.


-----------------------------------------------------------------

Every perl5 version of  File:File  has a sorted directory traversal
problem.

You sort the directory entries as you want with the "preprocess"
function.   The filenames are then passed to the "wanted" in the
sorted order, after which the sub-directories are traversed
IN THE REVERSE ORDER!!!!!



Looking at the code this was a direct result of directory entries
being pushed onto the stack, and then popping the entries in sequence.

For an example run the basic File:Find example program...

   http://www.sct.gu.edu.au/~anthony/info/perl/Find_File_testcase.pl

on any directory with a sub-directory structure.  The files are
listed alphabetically, but directorys are traversed in reverse alphabetical
order.

This is also the case when no "preprocess" function is supplied, in which case
files are handled in creation order, and directories traversed in reverse
creation order.



The following simple context diff patch....

For perl 5.6.1 File::Find.pm
   http://www.sct.gu.edu.au/~anthony/info/perl/Find::File.pm.perl5.6.diff

For perl 5.8.0 File::Find.pm
   http://www.sct.gu.edu.au/~anthony/info/perl/Find::File.pm.perl5.8.diff

Will fix the directory traversal problem by inserting directories onto the
traversal stack such that later they will be handled in the same order in
which they were seen for the current directory, without changing the order
of existing entries still awaiting processing on the stack.


  Anthony Thyssen ( System Programmer )    http://www.sct.gu.edu.au/~anthony/
 -----------------------------------------------------------------------------
   We will encourage you to develop the three great virtues of
       a programmer :   laziness, impatience and hubris. 
                                      --- Larry Wall - "Programming Perl"
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.sct.gu.edu.au/~anthony/


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=low
---
Site configuration information for perl v5.8.0:

Configured by bhcompile at Tue Feb 18 22:17:47 EST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.20-2.48smp, archname=i386-linux-thread-multi
    uname='linux stripples.devel.redhat.com 2.4.20-2.48smp #1 smp thu feb 13 11:44:55 est 2003 i686 i686 i386 gnulinux '
    config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -g -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Dotherlibdirs=/usr/lib/perl5/5.8.0 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr'
    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='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -march=i386 -mcpu=i686 -g',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.2.2 20030213 (Red Hat Linux 8.0 3.2.2-1)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
    libc=/lib/libc-2.3.1.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.3.1'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    MAINT18379

---
@INC for perl v5.8.0:
    /home/anthony/lib/perl5
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0
    .

---
Environment for perl v5.8.0:
    HOME=/home/anthony
    LANG (unset)
    LANGUAGE (unset)
    LC_COLLATE=C
    LD_LIBRARY_PATH=/opt/lib:/usr/local/lib:/usr/lib:/lib:/usr/X11R6/lib:/usr/java/j2re1.4.1_02/lib
    LOGDIR (unset)
    PATH=/home/anthony/bin/functions:/home/anthony/bin/local:/home/anthony/bin/l_wumpus:/home/anthony/bin/scripts:/home/anthony/bin/x_scripts:/home/anthony/bin/b_linux:/home/anthony/bin/x_linux:/home/anthony/bin/www:/home/anthony/bin/admin:/home/anthony/icons/support/scripts:/home/anthony/games:/home/anthony/bin/geom3d:/home/anthony/apps/rfb_linux:/opt/bin:/usr/local/bin:/usr/bin:/bin:/opt/sbin:/opt/etc:/sbin:/usr/sbin:/usr/bin/mh:/usr/games:/usr/X11R6/bin:/usr/java/j2re1.4.1_02/bin:.
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About