eval {
local $SIG{'__DIE__'};
+
$self->lock;
$self->_engine->setup_fh( $self );
+ $self->_storage->set_inode;
$self->unlock;
}; if ( $@ ) {
my $e = $@;
$class = 'DBM::Deep::Engine::Sector::Scalar';
}
-# if ( $blist->has_md5( $key_md5 ) ) {
-# $blist->load_data_for( $key_md5 )->free;
-# }
+ if ( $blist->has_md5( $key_md5 ) ) {
+ $blist->get_data_for( $key_md5 )->free;
+ }
my $value_sector = $class->new({
engine => $self,
}
}
- # We have to make sure we don't mess up when autoflush isn't turned on
- $self->storage->set_inode;
-
return 1;
}
my $old_head = $self->storage->read_at( $self->chains_loc + $chains_offset, $self->byte_size );
- $self->storage->print_at( $self->chains_loc + $offset,
+ $self->storage->print_at( $self->chains_loc + $chains_offset,
pack( $StP{$self->byte_size}, $offset ),
);
# Save the location so that we can free the data
my $location = $self->get_data_location_for( $idx );
+ my $key_sector = $self->get_key_for( $idx );
my $spot = $self->offset + $self->base_size + $idx * $self->bucket_size;
$engine->storage->print_at( $spot,
chr(0) x $self->bucket_size,
);
+ $key_sector->free;
+
my $data_sector = $self->engine->_load_sector( $location );
my $data = $data_sector->data;
-
- # Free the data (somehow)
$data_sector->free;
return $data;
sub set_inode {
my $self = shift;
- unless ( $self->{inode} ) {
+ unless ( defined $self->{inode} ) {
my @stats = stat($self->{fh});
$self->{inode} = $stats[1];
$self->{end} = $stats[7];
return $loc;
}
-#sub release_space {
-# my $self = shift;
-# my ($size, $loc) = @_;
-#
-# local($/,$\);
-#
-# my $next_loc = 0;
-#
-# my $fh = $self->{fh};
-# seek( $fh, $loc + $self->{file_offset}, SEEK_SET );
-# print( $fh SIG_FREE
-# . pack($self->{long_pack}, $size )
-# . pack($self->{long_pack}, $next_loc )
-# );
-#
-# return;
-#}
-
##
# If db locking is set, flock() the db file. If called multiple
# times before unlock(), then the same number of unlocks() must
# double-check file inode, in case another process
# has optimize()d our file while we were waiting.
- if ($stats[1] != $self->{inode}) {
+ if (defined($self->{inode}) && $stats[1] != $self->{inode}) {
$self->close;
$self->open;
is( $db->{x}, 'b', 'and it was stored' );
}
-
{
open my $fh, '<', $filename;
my $db = DBM::Deep->new({
+++ /dev/null
-use strict;
-
-use Test::More tests => 3;
-use t::common qw( new_fh );
-
-use_ok( 'DBM::Deep' );
-
-my ($fh, $filename) = new_fh();
-my $db = DBM::Deep->new({
- file => $filename,
- autoflush => 1,
-});
-
-$db->{foo} = 'abcd';
-
-my $s1 = -s $filename;
-
-delete $db->{foo};
-
-my $s2 = -s $filename;
-
-is( $s2, $s1, "delete doesn't recover freespace" );
-
-$db->{bar} = 'a';
-
-my $s3 = -s $filename;
-
-TODO: {
- local $TODO = "Freespace manager doesn't work yet";
- is( $s3, $s1, "Freespace is reused" );
-}
my $size = -s $filename;
$db->{foo} = '2345';
-TODO: {
- local $TODO = "Still writing freespace code";
cmp_ok( $size, '==', -s $filename, "Overwrite doesn't change size" );
-}
$size = -s $filename;
delete $db->{foo};
$size = -s $filename;
$db->{bar} = '2345';
-TODO: {
- local $TODO = "Still writing freespace code";
cmp_ok( $size, '==', -s $filename, "Added a new key after a delete reuses space" );
-}