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' );
}
$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 );
}
}
# 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;
$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;
$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 );
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;
$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;
$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 );