From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 092681F51A for ; Tue, 17 Oct 2023 23:38:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1697585897; bh=vEXsFkyn40i+bNZP5iPFdE3fe2hMSu4MHCKSC01s9CM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=C+W4i1zuKLapsF4YnKOpE4tx/LSePTRYy0Fu9h5kRfDbRd4dET7IoV8zBPhJbMhl1 xkhBFa7/riRdZ/b2PWSRYvcaCSACXMBTEAL0FrdVJ6/CFEpv7hWlklit9oKYdS8LIn k2eJuM8zjZvk3QHCLB6b6ClhUo1qH+uR42AZZuC4= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 06/30] lei_mirror: use read_all Date: Tue, 17 Oct 2023 23:37:51 +0000 Message-ID: <20231017233815.1637932-7-e@80x24.org> In-Reply-To: <20231017233815.1637932-1-e@80x24.org> References: <20231017233815.1637932-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This gives us better error checking for regular files. --- lib/PublicInbox/LeiMirror.pm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm index b402eb5f..47fb767b 100644 --- a/lib/PublicInbox/LeiMirror.pm +++ b/lib/PublicInbox/LeiMirror.pm @@ -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) };