From 19b791f4894efcb6e545a6b51c8147298363358f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 17 Oct 2023 23:37:52 +0000 Subject: use read_all in more places to improve safety `readline' ops may not detect errors on partial reads. This saves us some code to reduce cognitive overhead for readers. We'll also support reusing a destination buffers so it can work more nicely with existing code. --- script/public-inbox-init | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'script/public-inbox-init') diff --git a/script/public-inbox-init b/script/public-inbox-init index b3a16cfb..33bee310 100755 --- a/script/public-inbox-init +++ b/script/public-inbox-init @@ -125,13 +125,14 @@ my $auto_unlink = PublicInbox::OnDestroy->new($$, sub { unlink $lockfile }); my $perm = 0644 & ~umask; my %seen; if (-e $pi_config) { + require PublicInbox::Git; open(my $oh, '<', $pi_config) or die "unable to read $pi_config: $!\n"; my @st = stat($oh); $perm = $st[2]; defined $perm or die "(f)stat failed on $pi_config: $!\n"; chmod($perm & 07777, $fh) or die "(f)chmod failed on future $pi_config: $!\n"; - defined(my $old = do { local $/; <$oh> }) or die "read $pi_config: $!\n"; + my $old = PublicInbox::Git::read_all($oh); print $fh $old or die "failed to write: $!\n"; close $oh or die "failed to close $pi_config: $!\n"; -- cgit v1.2.3-24-ge0c7