From: rkinyon Date: Wed, 19 Apr 2006 15:44:18 +0000 (+0000) Subject: Fixed a bad dependency version X-Git-Tag: 0-99_01~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aa83bc1e6fccd5f036255776058617f8657c7c08;p=dbsrgits%2FDBM-Deep.git Fixed a bad dependency version Fixed a bug where the transaction_offset wasn't being modified by the file_offset --- diff --git a/Build.PL b/Build.PL index 5c23217..29d1754 100644 --- a/Build.PL +++ b/Build.PL @@ -16,7 +16,7 @@ my $build = Module::Build->new( build_requires => { 'File::Path' => '0.01', 'File::Temp' => '0.01', - 'Test::Deep' => '0.94', + 'Test::Deep' => '0.094', 'Test::More' => '0.47', 'Test::Exception' => '0.21', }, diff --git a/lib/DBM/Deep.pm b/lib/DBM/Deep.pm index 425012d..13259f7 100644 --- a/lib/DBM/Deep.pm +++ b/lib/DBM/Deep.pm @@ -401,6 +401,7 @@ sub STORE { my $self = shift->_get_self; my ($key, $value, $orig_key) = @_; + if ( $^O ne 'MSWin32' && !_is_writable( $self->_fh ) ) { $self->_throw_error( 'Cannot write to a readonly filehandle' ); } @@ -432,9 +433,10 @@ sub STORE { $rhs = "bless $rhs, '$c'"; } - flock( $afh, LOCK_EX ); - print( $afh "$lhs = $rhs; # STORE " . localtime(time) . "\n" ); - flock( $afh, LOCK_UN ); + $self->_fileobj->audit( "$lhs = $rhs;" ); +# flock( $afh, LOCK_EX ); +# print( $afh "$lhs = $rhs; # " . localtime(time) . "\n" ); +# flock( $afh, LOCK_UN ); } } diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm index 6c8e959..309c274 100644 --- a/lib/DBM/Deep/Engine.pm +++ b/lib/DBM/Deep/Engine.pm @@ -192,11 +192,7 @@ sub setup_fh { # File is empty -- write header and master index ## if (!$bytes_read) { - if ( my $afh = $self->_fileobj->{audit_fh} ) { - flock( $afh, LOCK_EX ); - print( $afh "# Database created on " . localtime(time) . "\n" ); - flock( $afh, LOCK_UN ); - } + $self->_fileobj->audit( "# Database created on" ); $self->write_file_header; diff --git a/lib/DBM/Deep/File.pm b/lib/DBM/Deep/File.pm index 651ec55..97b9463 100644 --- a/lib/DBM/Deep/File.pm +++ b/lib/DBM/Deep/File.pm @@ -186,6 +186,27 @@ sub set_transaction_offset { $self->{transaction_offset} = shift; } +sub audit { + my $self = shift; + + if ( my $afh = $self->{audit_fh} ) { + my ($string) = @_; + + flock( $afh, LOCK_EX ); + + if ( $string =~ /^#/ ) { + print( $afh "$string " . localtime(time) . "\n" ); + } + else { + print( $afh "$string # " . localtime(time) . "\n" ); + } + + flock( $afh, LOCK_UN ); + } + + return 1; +} + sub begin_transaction { my $self = shift; @@ -193,7 +214,7 @@ sub begin_transaction { $self->lock; - seek( $fh, $self->{transaction_offset}, SEEK_SET ); + seek( $fh, $self->{transaction_offset} + $self->{file_offset}, SEEK_SET ); my $buffer; read( $fh, $buffer, 4 ); $buffer = unpack( 'N', $buffer ); @@ -205,7 +226,7 @@ sub begin_transaction { last; } - seek( $fh, $self->{transaction_offset}, SEEK_SET ); + seek( $fh, $self->{transaction_offset} + $self->{file_offset}, SEEK_SET ); print( $fh pack( 'N', $buffer ) ); $self->unlock; @@ -220,14 +241,14 @@ sub end_transaction { $self->lock; - seek( $fh, $self->{transaction_offset}, SEEK_SET ); + seek( $fh, $self->{transaction_offset} + $self->{file_offset}, SEEK_SET ); my $buffer; read( $fh, $buffer, 4 ); $buffer = unpack( 'N', $buffer ); # Unset $self->{transaction_id} bit - seek( $fh, $self->{transaction_offset}, SEEK_SET ); + seek( $fh, $self->{transaction_offset} + $self->{file_offset}, SEEK_SET ); print( $fh pack( 'N', $buffer ) ); $self->unlock; @@ -242,7 +263,7 @@ sub current_transactions { $self->lock; - seek( $fh, $self->{transaction_offset}, SEEK_SET ); + seek( $fh, $self->{transaction_offset} + $self->{file_offset}, SEEK_SET ); my $buffer; read( $fh, $buffer, 4 ); $buffer = unpack( 'N', $buffer );