From: Eric Wong Date: Tue, 17 Oct 2023 23:37:50 +0000 (+0000) Subject: import: use read_all to detect short reads X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f0af86d00021d1bbdfb09c28e48e5b81b8240fa;p=thirdparty%2Fpublic-inbox.git import: use read_all to detect short reads Our Import package was depending on Git, anyways. --- diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index 6bb2c66d8..fb70b91b6 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -21,6 +21,7 @@ use POSIX qw(strftime); use autodie qw(read close socketpair); use Carp qw(croak); use Socket qw(AF_UNIX SOCK_STREAM); +use PublicInbox::Git qw(read_all); sub default_branch () { state $default_branch = do { @@ -114,8 +115,7 @@ sub _cat_blob ($$) { local $/ = "\n"; my $info = <$io> // die "EOF from fast-import / cat-blob: $!"; $info =~ /\A[a-f0-9]{40,} blob ([0-9]+)\n\z/ or return; - my $n = read($io, my $buf, my $len = $1 + 1); - $n == $len or croak "cat-blob: short read: $n < $len"; + my $buf = read_all($io, my $len = $1 + 1); my $lf = chop $buf; croak "bad read on final byte: <$lf>" if $lf ne "\n"; \$buf; @@ -562,9 +562,7 @@ sub replace_oids { } elsif (/^data ([0-9]+)/) { # only commit message, so $len is small: push @buf, $_; - my $n = read($rd, my $buf, my $len = $1); - $len == $n or croak "short read ($n < $len)"; - push @buf, $buf; + push @buf, read_all($rd, my $len = $1); } elsif (/^M 100644 ([a-f0-9]+) (\w+)/) { my ($oid, $path) = ($1, $2); $tree->{$path} = 1;