Subject: | Suggestion: version number 2 with fixed sizes for version, length and start_of_file |
Date: | Sun, 14 Apr 2013 13:13:41 +0200 |
To: | bug-file-roundrobin <bug-file-roundrobin [...] rt.cpan.org> |
From: | Peter Valdemar Mørch <peter [...] morch.com> |
Right now, when loading a file, the three fields are loaded with <>,
and $/ set to "\x00".
If the file happens not to be created by File::RoundRobin.pm that'll
create warnings and hang for most text files.
Here is the little test program I'm using:
#!/usr/bin/perl -w
use File::RoundRobin;
my $rrfile = File::RoundRobin->new(
path => 'log.txt',
size => '1M',
mode => 'append',
);
$rrfile->print("something\n");
Here are the results from running it: Starting with an empty file
(touch-ed), it creates warnings and hangs. Starting with a copy of
/etc/passwd, on the first run of rr.pl it creates a bunch of warnings,
but successfully exists. On the next invocation, it hangs.
In all these cases, I propose that File::RoundRobin->new() should
detect that the file is not a valid File::RoundRobin file and return
undef. The easiest way to do that is to ensure that the version, size
and length fields have a predictable length (e.g. also with a magic
number to improve verification without too much of a performance hit)
and return undef if these predictable properties are not met. (I'm not
sure what tie() should do. Perhaps return undef?)
What do you think?
Regards,
Peter
tony@pvm:~/git/capmon/inc> rm -f log.txt ; touch log.txt
tony@pvm:~/git/capmon/inc> perl -w rr.pl
Use of uninitialized value $version in length at
/usr/share/perl5/File/RoundRobin.pm line 494.
Use of uninitialized value $size in length at
/usr/share/perl5/File/RoundRobin.pm line 494.
Use of uninitialized value $start_point in length at
/usr/share/perl5/File/RoundRobin.pm line 494.
Use of uninitialized value $size in substitution (s///) at
/usr/share/perl5/File/RoundRobin.pm line 496.
Use of uninitialized value $start_point in substitution (s///) at
/usr/share/perl5/File/RoundRobin.pm line 497.
Use of uninitialized value $start_point in addition (+) at
/usr/share/perl5/File/RoundRobin.pm line 499.
Use of uninitialized value $size in addition (+) at
/usr/share/perl5/File/RoundRobin.pm line 502.
Use of uninitialized value $start_point in addition (+) at
/usr/share/perl5/File/RoundRobin.pm line 502.
^C
tony@pvm:~/git/capmon/inc> rm -f log.txt ; cp /etc/passwd log.txt
tony@pvm:~/git/capmon/inc> perl -w rr.pl
Use of uninitialized value $size in length at
/usr/share/perl5/File/RoundRobin.pm line 494, <$fh> chunk 1.
Use of uninitialized value $start_point in length at
/usr/share/perl5/File/RoundRobin.pm line 494, <$fh> chunk 1.
Use of uninitialized value $size in substitution (s///) at
/usr/share/perl5/File/RoundRobin.pm line 496, <$fh> chunk 1.
Use of uninitialized value $start_point in substitution (s///) at
/usr/share/perl5/File/RoundRobin.pm line 497, <$fh> chunk 1.
Use of uninitialized value $start_point in addition (+) at
/usr/share/perl5/File/RoundRobin.pm line 499, <$fh> chunk 1.
Use of uninitialized value $size in addition (+) at
/usr/share/perl5/File/RoundRobin.pm line 502, <$fh> line 1.
Use of uninitialized value $start_point in addition (+) at
/usr/share/perl5/File/RoundRobin.pm line 502, <$fh> line 1.
this should still go onto stdout
tony@pvm:~/git/capmon/inc> perl -w rr.pl
^C
--
Peter Valdemar Mørch
http://www.morch.com