]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei_mirror: use write_file to append configs
authorEric Wong <e@80x24.org>
Mon, 10 Feb 2025 21:09:33 +0000 (21:09 +0000)
committerEric Wong <e@80x24.org>
Tue, 11 Feb 2025 19:08:12 +0000 (19:08 +0000)
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.

lib/PublicInbox/LeiMirror.pm

index f87cdc51b5c441ea864f867ae69a2b57502188d2..0f14cebae4e85dac7e357eef0adc7d78da01423f 100644 (file)
@@ -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 ];