{
my $header_fixed = length( SIG_FILE ) + 1 + 4 + 4;
- my $this_header_version = 2;
+ my $this_file_version = 2;
sub _write_file_header {
my $self = shift;
$self->storage->print_at( $loc,
SIG_FILE,
SIG_HEADER,
- pack('N', $this_header_version), # At this point, we're at 9 bytes
- pack('N', $header_var), # header size
+ pack('N', $this_file_version), # At this point, we're at 9 bytes
+ pack('N', $header_var), # header size
# --- Above is $header_fixed. Below is $header_var
pack('C', $self->byte_size),
pack('C', $self->max_buckets),
my $buffer = $self->storage->read_at( 0, $header_fixed );
return unless length($buffer);
- my ($file_signature, $sig_header, $header_version, $size) = unpack(
+ my ($file_signature, $sig_header, $file_version, $size) = unpack(
'A4 A N N', $buffer
);
DBM::Deep->_throw_error( "Pre-1.00 file version found" );
}
- unless ( $header_version == $this_header_version ) {
+ unless ( $file_version == $this_file_version ) {
$self->storage->close;
DBM::Deep->_throw_error(
- "Wrong file version found - " . $header_version .
- " - expected " . $this_header_version
+ "Wrong file version found - " . $file_version .
+ " - expected " . $this_file_version
);
}
##
$|++;
use strict;
-use Test::More tests => 6;
+use Test::More tests => 8;
use Test::Exception;
use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
-my ($fh, $filename) = new_fh();
-
##
# test a corrupted file
##
-open FH, ">$filename";
-print FH 'DPDB';
-close FH;
-throws_ok {
- DBM::Deep->new( $filename );
-} qr/DBM::Deep: Pre-1.00 file version found/, "Fail if there's a bad header";
+{
+ my ($fh, $filename) = new_fh();
+
+ open FH, ">$filename";
+ print FH 'DPDB';
+ close FH;
+
+ throws_ok {
+ DBM::Deep->new( $filename );
+ } qr/DBM::Deep: Pre-1.00 file version found/, "Fail if there's a bad header";
+}
{
my ($fh, $filename) = new_fh();
DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_HASH )
} qr/DBM::Deep: File type mismatch/, "Fail if we try and open an array file with a hash";
}
+
+{
+ throws_ok {
+ DBM::Deep->new( 't/old_versions/db.0.983' );
+ } qr/DBM::Deep: Pre-1.00 file version found/, "Fail if opening a pre-1.00 file";
+}
+
+{
+ throws_ok {
+ DBM::Deep->new( 't/old_versions/db.0.99_04' );
+ } qr/DBM::Deep: Wrong file version found - 1 - expected 2/, "Fail if opening a file version 1";
+}