about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-11-28 05:31:49 +0000
committerEric Wong <e@80x24.org>2022-11-28 23:38:56 +0000
commit62269f4547882a20b022f6453dbdd7b78f4685c1 (patch)
tree39c2cffa0c7340d7e0c7573ec812e47054d82730 /lib/PublicInbox
parentd58adce592aa4fa719d095b6f3f05665a2f7b394 (diff)
downloadpublic-inbox-62269f4547882a20b022f6453dbdd7b78f4685c1.tar.gz
We don't want to be clobbering permissions when changing to
relative paths.  Furthermore, we can avoid writing to the
alternates file if there are no changes.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/LeiMirror.pm28
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index d6aca800..829740bc 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -113,9 +113,9 @@ sub clone_cmd {
         @cmd;
 }
 
-sub ft_rename ($$$) {
-        my ($ft, $dst, $open_mode) = @_;
-        my @st = stat($dst);
+sub ft_rename ($$$;$) {
+        my ($ft, $dst, $open_mode, $fh) = @_;
+        my @st = stat($fh // $dst);
         my $mode = @st ? ($st[2] & 07777) : ($open_mode & ~umask);
         chmod($mode, $ft) or croak "E: chmod($ft): $!";
         require File::Copy;
@@ -565,19 +565,21 @@ sub v1_done { # called via OnDestroy
                 run_die([qw(git config -f), "$dst/config", 'gitweb.owner', $o]);
         }
         my $o = "$dst/objects";
-        if (open(my $fh, '<', "$o/info/alternates")) {
+        if (open(my $fh, '<', my $fn = "$o/info/alternates")) {;
                 my $base = File::Spec->rel2abs($o);
-                chomp(my @l = <$fh>);
+                my @l = <$fh>;
+                my $ft;
                 for (@l) {
-                        $_ = File::Spec->abs2rel($_, $base) if m!\A/!;
-                        $_ .= "\n";
+                        next unless m!\A/!;
+                        $_ = File::Spec->abs2rel($_, $base);
+                        $ft //= File::Temp->new(TEMPLATE => '.XXXX',
+                                                DIR => "$o/info");
+                }
+                if ($ft) {
+                        print $ft @l or die "print($ft): $!";
+                        $ft->flush or die "flush($ft): $!";
+                        ft_rename($ft, $fn, 0666, $fh);
                 }
-                my $f = File::Temp->new(TEMPLATE => '.XXXX', DIR => "$o/info");
-                print $f @l;
-                $f->flush or die "flush($f): $!";
-                rename($f->filename, "$o/info/alternates") or
-                        die "rename($f, $o/info/alternates): $!";
-                $f->unlink_on_destroy(0);
         }
         pack_refs($self, $dst) if delete $self->{-do_pack_refs};
         eval { set_description($self) };