]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Msgmap.pm
msgmap: fix atfork_* callbacks
[public-inbox.git] / lib / PublicInbox / Msgmap.pm
index e86fb8541bb3e6c0e534317d9058c2809a7473da..9d2ef0dc5455f2c239ad54d283fe24a272d23bdc 100644 (file)
@@ -229,29 +229,30 @@ sub mid_set {
 
 sub DESTROY {
        my ($self) = @_;
-       delete $self->{dbh};
-       my $f = $self->{filename};
+       my $dbh = $self->{dbh} or return;
        if (($self->{pid} // 0) == $$) {
+               my $f = $dbh->sqlite_db_filename;
                unlink $f or warn "failed to unlink $f: $!\n";
        }
 }
 
 sub atfork_parent {
        my ($self) = @_;
-       $self->{pid} or die "not a temporary clone\n";
-       delete $self->{dbh} and die "tmp_clone dbh not prepared for parent";
+       $self->{pid} or die 'BUG: not a temporary clone';
+       $self->{dbh} and die 'BUG: tmp_clone dbh not prepared for parent';
+       defined($self->{filename}) or die 'BUG: {filename} not defined';
        my $dbh = $self->{dbh} = PublicInbox::Over::dbh_new($self, 1);
        $dbh->do('PRAGMA synchronous = OFF');
 }
 
 sub atfork_prepare {
        my ($self) = @_;
-       $self->{pid} or die "not a temporary clone\n";
-       $self->{pid} == $$ or
-               die "BUG: atfork_prepare not called from $self->{pid}\n";
-       $self->{dbh} or die "temporary clone not open\n";
+       my $pid = $self->{pid} or die 'BUG: not a temporary clone';
+       $pid == $$ or die "BUG: atfork_prepare not called by $pid";
+       my $dbh = $self->{dbh} or die 'BUG: temporary clone not open';
+
        # must clobber prepared statements
-       %$self = (filename => $self->{filename}, pid => $$);
+       %$self = (filename => $dbh->sqlite_db_filename, pid => $pid);
 }
 
 sub skip_artnum {