From: rkinyon Date: Tue, 7 Mar 2006 21:23:17 +0000 (+0000) Subject: Converted more to use _request_space() ... still more to go X-Git-Tag: 0-99_01~71 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c9ec091a0d2b7724df5ccaa1de0f4ca06b45a28b;p=dbsrgits%2FDBM-Deep.git Converted more to use _request_space() ... still more to go --- diff --git a/lib/DBM/Deep.pm b/lib/DBM/Deep.pm index 1726d4f..ea065ba 100644 --- a/lib/DBM/Deep.pm +++ b/lib/DBM/Deep.pm @@ -649,10 +649,7 @@ sub new { my $self = bless { autobless => undef, autoflush => undef, - #XXX It should be this in order to work with the initial create_tag(), - #XXX but it's not ... it works out because of the stat() in setup_fh(), - #XXX but that's not good. - end => 0, #length(DBM::Deep->SIG_FILE), + end => 0, fh => undef, file => undef, file_offset => 0, diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm index 1cced74..daf82d2 100644 --- a/lib/DBM/Deep/Engine.pm +++ b/lib/DBM/Deep/Engine.pm @@ -119,15 +119,17 @@ sub setup_fh { # File is empty -- write signature and master index ## if (!$bytes_read) { - seek($fh, 0 + $obj->_root->{file_offset}, SEEK_SET); + my $loc = $self->_request_space( $obj, length( SIG_FILE ) ); + seek($fh, $loc + $obj->_root->{file_offset}, SEEK_SET); print( $fh SIG_FILE); - $obj->_root->{end} = length( SIG_FILE ); - - $obj->{base_offset} = $self->_request_space($obj, $self->{index_size}); + $obj->{base_offset} = $self->_request_space( + $obj, $self->{index_size}, + ); $self->create_tag( - $obj, $obj->_base_offset, $obj->_type, chr(0) x $self->{index_size}, + $obj, $obj->_base_offset, $obj->_type, + chr(0) x $self->{index_size}, ); # Flush the filehandle @@ -178,8 +180,6 @@ sub open { my $self = shift; my ($obj) = @_; - if (defined($obj->_fh)) { $self->close_fh( $obj ); } - # Theoretically, adding O_BINARY should remove the need for the binmode # Of course, testing it is going to be ... interesting. my $flags = O_RDWR | O_CREAT | O_BINARY; @@ -900,6 +900,7 @@ sub _request_space { my ($obj, $size) = @_; my $loc = $obj->_root->{end}; + $obj->_root->{end} += $size; return $loc; }