From: Eric Wong Date: Mon, 10 Feb 2025 21:09:33 +0000 (+0000) Subject: lei_mirror: use write_file to append configs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b7ab3a41aa59dbc7891dfbc3d1e8d52264a85fc;p=thirdparty%2Fpublic-inbox.git lei_mirror: use write_file to append configs It saves us a few lines of code and reduces unnecessary error checking since the close done by write_file aleady does autodie for error checking. --- diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm index f87cdc51b..0f14cebae 100644 --- a/lib/PublicInbox/LeiMirror.pm +++ b/lib/PublicInbox/LeiMirror.pm @@ -447,21 +447,17 @@ sub fgrp_fetch_all { # update the config atomically via O_APPEND while # respecting git-config locking sysopen(my $lk, "$f.lock", O_CREAT|O_EXCL|O_WRONLY); - open my $fh, '>>', $f; - $fh->autoflush(1); - my $buf = ''; + my @buf; if (@$old) { - $buf = "[fetch]\n\thideRefs = refs\n"; - $buf .= join('', map { + @buf = ("[fetch]\n\thideRefs = refs\n", map { "\thideRefs = !refs/remotes/" . "$_->{-remote}/\n"; } @$old); } - $buf .= join('', "[remotes]\n", + push @buf, "[remotes]\n", (map { "\t$grp = $_->{-remote}\n" } @$old), - (map { "\t$grp = $_->{-remote}\n" } @$new)); - print $fh $buf or die "print($f): $!"; - close $fh; + (map { "\t$grp = $_->{-remote}\n" } @$new); + write_file '>>', $f, @buf; unlink("$f.lock"); } $cmd = [ @git, "--git-dir=$osdir", @fetch, $grp ];