perlquestion
djw
I have written a small application to collect file/path information recursively from a root path given during execution. I collect this information of each file (using File::stat and File::Find):
<br>
<ul>
<li>current directory</li>
<li>file size (size)</li>
<li>file create time (ctime)</li>
<li>file modify time (mtime)</li>
<li>file access time (atime)</li>
</ul>
<br>
I store that information in a mysql database.
For some reason it is returning a negative value from File::stat's size method on specific files (test system is win32 and the same files are negative when I run the program again). One of the files is a system file (pagefile.sys), but the rest are simply mpeg's. Each file is over 500MB in size. There are other files collected that record the correct size and are 500MB or greater, so it doesn't seem to be a file size problem. There are also other files in the same directories as the problem files and have properly recorded file sizes. There isn't a permission problem on these files.
<readmore>
Here is a quick snippet:<br>
<code>
use File::stat qw(:FIELDS );
use File::Find qw( finddepth );
# stuff...
finddepth \&gatherData, $dir;
# stuff...
sub gatherData {
if (-f) {
stat($_);
# -----------
# get the current directory
# and file names
my $cdir = $File::Find::dir;
my $file = $_;
# -----------
# put that into our data
# hash for input later
$data{$cdir}{$file}{size} = $st_size;
$data{$cdir}{$file}{ctime} = $st_ctime;
$data{$cdir}{$file}{mtime} = $st_mtime;
$data{$cdir}{$file}{atime} = $st_atime;
}
}
</code>
Then I just iterate over the hash to enter all the data into the database (no modification or calculations etc). Also, there are no errors or warnings during or after execution.
<br><br>
Here is what the data looks like in the db:<br><br>
<code>
mysql> select file_id, file, size from files where size < 0;
+---------+--------------+-------------+
| file_id | file | size |
+---------+--------------+-------------+
| 635609 | fooo 3.mpg | -773913892 |
| 635608 | baaar 1.mpg | -529282490 |
| 635603 | foooo 3.mpg | -2035912248 |
| 611851 | pagefile.sys | -2147483648 |
+---------+--------------+-------------+
4 rows in set (0.32 sec)
</code>
I have around 194 K files listed in the files table (from two different systems), and all of these files are from the same system.<br><br>
Any suggestions on how I should solve this?<br><br>
Thanks,
<br>
<a href="http://www.perlmonks.org/index.pl?node_id=16711&lastnode_id=1072">djw</a>
</readmore>