about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiALE.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox/LeiALE.pm')
-rw-r--r--lib/PublicInbox/LeiALE.pm38
1 files changed, 16 insertions, 22 deletions
diff --git a/lib/PublicInbox/LeiALE.pm b/lib/PublicInbox/LeiALE.pm
index cc9a2095..ce03f5b4 100644
--- a/lib/PublicInbox/LeiALE.pm
+++ b/lib/PublicInbox/LeiALE.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # All Locals Ever: track lei/store + externals ever used as
@@ -6,11 +6,12 @@
 # and --only targets that haven't been through "lei add-external".
 # Typically: ~/.cache/lei/all_locals_ever.git
 package PublicInbox::LeiALE;
-use strict;
-use v5.10.1;
+use v5.12;
 use parent qw(PublicInbox::LeiSearch PublicInbox::Lock);
 use PublicInbox::Git;
+use autodie qw(close open rename seek truncate);
 use PublicInbox::Import;
+use PublicInbox::OnDestroy;
 use PublicInbox::LeiXSearch;
 use Fcntl qw(SEEK_SET);
 
@@ -41,11 +42,11 @@ sub over {} # undef for xoids_for
 
 sub overs_all { # for xoids_for (called only in lei workers?)
         my ($self) = @_;
-        my $pid = $$;
-        if (($self->{owner_pid} // $pid) != $pid) {
+        my $fgen = $PublicInbox::OnDestroy::fork_gen ;
+        if (($self->{fgen} // $fgen) != $fgen) {
                 delete($_->{over}) for @{$self->{ibxish}};
         }
-        $self->{owner_pid} = $pid;
+        $self->{fgen} = $fgen;
         grep(defined, map { $_->over } @{$self->{ibxish}});
 }
 
@@ -54,11 +55,7 @@ sub refresh_externals {
         $self->git->cleanup;
         my $lk = $self->lock_for_scope;
         my $cur_lxs = ref($lxs)->new;
-        my $orig = do {
-                local $/;
-                readline($self->{lockfh}) //
-                                die "readline($self->{lock_path}): $!";
-        };
+        my $orig = PublicInbox::IO::read_all $self->{lockfh};
         my $new = '';
         my $old = '';
         my $gone = 0;
@@ -81,19 +78,16 @@ sub refresh_externals {
         if ($new ne '' || $gone) {
                 $self->{lockfh}->autoflush(1);
                 if ($gone) {
-                        seek($self->{lockfh}, 0, SEEK_SET) or die "seek: $!";
-                        truncate($self->{lockfh}, 0) or die "truncate: $!";
+                        seek($self->{lockfh}, 0, SEEK_SET);
+                        truncate($self->{lockfh}, 0);
                 } else {
                         $old = '';
                 }
                 print { $self->{lockfh} } $old, $new or die "print: $!";
         }
-        $new = $old = '';
+        $new = '';
         my $f = $self->git->{git_dir}.'/objects/info/alternates';
-        if (open my $fh, '<', $f) {
-                local $/;
-                $old = <$fh> // die "readline($f): $!";
-        }
+        $old = PublicInbox::IO::try_cat $f;
         for my $x (@ibxish) {
                 $new .= $lei->canonpath_harder($x->git->{git_dir})."/objects\n";
         }
@@ -103,10 +97,10 @@ sub refresh_externals {
         # this needs to be atomic since child processes may start
         # git-cat-file at any time
         my $tmp = "$f.$$.tmp";
-        open my $fh, '>', $tmp or die "open($tmp): $!";
-        print $fh $new or die "print($tmp): $!";
-        close $fh or die "close($tmp): $!";
-        rename($tmp, $f) or die "rename($tmp, $f): $!";
+        open my $fh, '>', $tmp;
+        print $fh $new;
+        close $fh;
+        rename($tmp, $f)
 }
 
 1;