From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.1 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 9A3562019B for ; Mon, 28 Nov 2022 05:32:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1669613563; bh=Xt9fVPygHuf5YVbVIq36NTerKPoDpMwFKbPqxTlknqg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VIHp/SiUbmUbdkE1SAUwaePwgXLf+cwiy4a5+HDEhfZpljCOZGsUOK9V/zwWyRONZ vqBfg5nIVpUjGxxbKLEuGdvizAEMx6iGRLGR6vn88fgzEsZK7gYlnx4kCl3IX7acKY IJ865sqJtg+7tx6nnhfSJx6pHMrOmJByxGbQLY4U= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 52/95] lei_mirror: preserve permissions of existing alternates file Date: Mon, 28 Nov 2022 05:31:49 +0000 Message-Id: <20221128053232.291618-53-e@80x24.org> In-Reply-To: <20221128053232.291618-1-e@80x24.org> References: <20221128053232.291618-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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. --- lib/PublicInbox/LeiMirror.pm | 28 +++++++++++++++------------- 1 file 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) };