From: rkinyon Date: Tue, 7 Mar 2006 20:07:37 +0000 (+0000) Subject: Moved the flock to around the entire loop X-Git-Tag: 0-99_01~72 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6fde4ed2b948886e5cf014dc34073da199148096;p=dbsrgits%2FDBM-Deep.git Moved the flock to around the entire loop --- diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm index 542a4d3..1cced74 100644 --- a/lib/DBM/Deep/Engine.pm +++ b/lib/DBM/Deep/Engine.pm @@ -107,11 +107,10 @@ sub setup_fh { $self->open( $obj ) if !defined $obj->_fh; - unless ( $obj->{base_offset} ) { - my $fh = $obj->_fh; - - flock $fh, LOCK_EX; + my $fh = $obj->_fh; + flock $fh, LOCK_EX; + unless ( $obj->{base_offset} ) { seek($fh, 0 + $obj->_root->{file_offset}, SEEK_SET); my $signature; my $bytes_read = read( $fh, $signature, length(SIG_FILE)); @@ -157,8 +156,6 @@ sub setup_fh { $obj->_throw_error("File type mismatch"); } } - - flock $fh, LOCK_UN; } #XXX We have to make sure we don't mess up when autoflush isn't turned on @@ -168,6 +165,8 @@ sub setup_fh { $obj->_root->{end} = $stats[7]; } + flock $fh, LOCK_UN; + return 1; }