Converted more to use _request_space() ... still more to go
rkinyon [Tue, 7 Mar 2006 21:23:17 +0000 (21:23 +0000)]
lib/DBM/Deep.pm
lib/DBM/Deep/Engine.pm

index 1726d4f..ea065ba 100644 (file)
@@ -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,
index 1cced74..daf82d2 100644 (file)
@@ -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;
 }