From: rkinyon Date: Wed, 22 Mar 2006 04:36:52 +0000 (+0000) Subject: Added read_file_signature X-Git-Tag: 0-99_01~45 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e064ccd116a8de9ae5d1763eace1aaccaa2a8a1e;p=dbsrgits%2FDBM-Deep.git Added read_file_signature --- diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm index e9cbcbb..6262f4b 100644 --- a/lib/DBM/Deep/Engine.pm +++ b/lib/DBM/Deep/Engine.pm @@ -115,6 +115,26 @@ sub write_file_signature { return; } +sub read_file_signature { + my $self = shift; + my ($obj) = @_; + + my $fh = $obj->_fh; + + seek($fh, 0 + $obj->_root->{file_offset}, SEEK_SET); + my $signature; + my $bytes_read = read( $fh, $signature, length(SIG_FILE)); + + if ( $bytes_read ) { + unless ($signature eq SIG_FILE) { + $self->close_fh( $obj ); + $obj->_throw_error("Signature not found -- file is not a Deep DB"); + } + } + + return $bytes_read; +} + sub setup_fh { my $self = shift; my ($obj) = @_; @@ -125,9 +145,7 @@ sub setup_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)); + my $bytes_read = $self->read_file_signature( $obj ); ## # File is empty -- write signature and master index @@ -153,14 +171,6 @@ sub setup_fh { $obj->{base_offset} = $bytes_read; ## - # Check signature was valid - ## - unless ($signature eq SIG_FILE) { - $self->close_fh( $obj ); - $obj->_throw_error("Signature not found -- file is not a Deep DB"); - } - - ## # Get our type from master index signature ## my $tag = $self->load_tag($obj, $obj->_base_offset)