]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei_mirror: use read_all
authorEric Wong <e@80x24.org>
Tue, 17 Oct 2023 23:37:51 +0000 (23:37 +0000)
committerEric Wong <e@80x24.org>
Wed, 18 Oct 2023 20:50:24 +0000 (20:50 +0000)
This gives us better error checking for regular files.

lib/PublicInbox/LeiMirror.pm

index b402eb5f41263637737d189d98c2c5574d9ecb2b..47fb767b398c58ecfabf62d4b468ca0af9b80997 100644 (file)
@@ -16,7 +16,7 @@ use Carp qw(croak);
 use URI;
 use PublicInbox::Config qw(glob2re);
 use PublicInbox::Inbox;
-use PublicInbox::Git;
+use PublicInbox::Git qw(read_all);
 use PublicInbox::LeiCurl;
 use PublicInbox::OnDestroy;
 use PublicInbox::SHA qw(sha256_hex sha1_hex);
@@ -174,8 +174,7 @@ sub _get_txt_done { # returns true on error (non-fatal), undef on success
        return warn("# @$cmd failed (non-fatal)\n") if $cerr;
        seek($fh, SEEK_SET, 0);
        $self->{"mtime.$endpoint"} = (stat($fh))[9];
-       local $/;
-       $self->{"txt.$endpoint"} = <$fh>;
+       $self->{"txt.$endpoint"} = read_all($fh, -s _);
        undef; # success
 }
 
@@ -537,7 +536,7 @@ sub fp_done {
        seek($fh, SEEK_SET, 0);
        $self->{-ent} // die 'BUG: no -ent';
        my $A = $self->{-ent}->{fingerprint} // die 'BUG: no fingerprint';
-       my $B = sha1_hex(do { local $/; <$fh> } // die("read(show_ref): $!"));
+       my $B = sha1_hex(read_all($fh));
        return $cb->($self, @arg) if $A ne $B;
        $self->{lei}->qerr("# $self->{-key} up-to-date");
 }
@@ -734,7 +733,7 @@ sub up_fp_done {
        seek($fh, SEEK_SET, 0);
        $self->{-ent} // die 'BUG: no -ent';
        my $A = $self->{-ent}->{fingerprint} // die 'BUG: no fingerprint';
-       my $B = sha1_hex(do { local $/; <$fh> } // die("read(show_ref): $!"));
+       my $B = sha1_hex(read_all($fh));
        return if $A eq $B;
        $self->{-ent}->{fingerprint} = $B;
        push @{$self->{chg}->{fp_mismatch}}, $self->{-key};
@@ -948,7 +947,7 @@ failed to extract epoch number from $src
 sub decode_manifest ($$$) {
        my ($fh, $fn, $uri) = @_;
        my $js;
-       my $gz = do { local $/; <$fh> } // die "slurp($fn): $!";
+       my $gz = read_all($fh);
        gunzip(\$gz => \$js, MultiStream => 1) or
                die "gunzip($uri): $GunzipError\n";
        my $m = eval { PublicInbox::Config->json->decode($js) };