The eAuction Support Forums
https://www.everyscript.de/cgi-bin/yabb/YaBB.pl
eAuction 1.6.1.x >> Fixed Bugs >> readdir: file order
https://www.everyscript.de/cgi-bin/yabb/YaBB.pl?num=1108059668

Message started by Wotan on 02/10/05 at 19:21:07

Title: readdir: file order
Post by Wotan on 02/10/05 at 19:21:07

Hello,

today I moved my client's eAuction based web-site on a new hosting server (Fedora linux, perl 5.8.3). After this I got an error. Let me skip all the investigations I did, and show only the result.

The folder /cgi-bin/auctiondata/antiques1 has 3 files:
1110645496.dat, 1110645545.dat, 1110645936.dat.

I run a very simple script:
opendir THEDIR, "$config{'basepath'}$form{'category'}" or &oops("Category directory $form{'category'} could not be opened.");

my @test = readdir THEDIR;
my $file;
foreach $file (@test) {
 print '<br>:';
 print $file;
}

And the result is:
:..
:test
:1110645936.dat
:1110645545.dat
:.
:1110645496.dat

Please note that . and .. are not the very first entries. Consequently, the auction script fails when it tries to open the . file and read from it.

I found ~250 readdir in all the files, and wouldn't like to fix it manually. Any suggestions?

Thanks a lot,
Max

Title: Re: readdir: file order
Post by Dieter Werner on 02/11/05 at 11:28:20

Run this:

Code:
opendir THEDIR, "$config{'basepath'}$form{'category'}"
or die("Category directory $form{'category'} could not be opened.");

my @test = grep /\.dat$/, readdir THEDIR;
my $file;
foreach $file (@test) {
       print '<br>File: ';
       print $file;
}


or this:

Code:
opendir THEDIR, "$config{'basepath'}$form{'category'}"
or die("Category directory $form{'category'} could not be opened.");

readdir THEDIR for 0 .. 1;
my @test = readdir THEDIR;
my $file;
foreach $file (@test) {
       print '<br>File: ';
       print $file;
}


and let me know the result.


Title: Re: readdir: file order
Post by Wotan on 02/17/05 at 14:34:00

The first script produces the following (correct) result:

Code:
File: 1110645936.dat
File: 1110645545.dat
File: 1110645496.dat


The second doesn't work correctly:

Code:
File: 1110645545.dat
File: .
File: 1110645496.dat


Title: Re: readdir: file order
Post by Wotan on 02/17/05 at 14:35:56

Btw, here is more info about it
https://bugzilla.redhat.com/beta/show_bug.cgi?id=125545

Title: Re: readdir: file order
Post by Dieter Werner on 02/17/05 at 15:22:19

Be sure - it IS a Redhat-Bug ...
The file order of a directory has to be
.
..
filename_1
filename_x
filename_n

As far as I could read, they hold the structure of a directory in a hash - but a hash is unsorted.


Title: Re: readdir: file order
Post by Wotan on 02/17/05 at 17:07:52

Sorry, I am still not sure. Here is the PHP doc for readdir (I just don't have a perl doc).


Code:
Description
string readdir ( resource dir_handle)

Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem.


I.e. if a filesystem has the files unsorted, this is matter of the filesystem. You CAN'T relay on any order of the files actually.

Title: Re: readdir: file order
Post by Dieter Werner on 02/17/05 at 18:04:26


Wotan wrote:
Sorry, I am still not sure. Here is the PHP doc for readdir (I just don't have a perl doc).


Code:
Description
string readdir ( resource dir_handle)

Returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem.

Yes - but . and .. are the first files that have been created, haven't they.


Wotan wrote:
I.e. if a filesystem has the files unsorted, this is matter of the filesystem. You CAN'T relay on any order of the files actually.


No - as long as the files are returned in the order in which they are stored, so long . and .. are located on the first places.

But I think I can help to resolve this.
The code of 'sub read_dir' has to be changed in some parts.
It's not an act but currently I'm missing the time to do it.
Maybe next week ...

Title: Re: readdir: file order
Post by Dieter Werner on 02/18/05 at 10:52:07

This should do the job ...
search eAuction.pl for

Quote:
sub read_dir_range

search sub read_dir_range for the line

Code:
readdir THEDIR for 0 .. $trash;

and replace it with this line

Code:
$trash > 1 && do { readdir THEDIR for 0 .. $trash };

The eAuction Support Forums » Powered by YaBB 2.2!
YaBB © 2000-2007. All Rights Reserved.