From 22fca958a2a4d43d5ee4e006bfc046b72d76cae0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 22 May 2019 02:13:58 +0000 Subject: init: preserve permissions for git prior to 2.1.0 "git config" did not preserve permissions of the config file it modifies prior to git 2.1.0, so workaround that. --- script/public-inbox-init | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'script/public-inbox-init') diff --git a/script/public-inbox-init b/script/public-inbox-init index 5516e798..2cc704ce 100755 --- a/script/public-inbox-init +++ b/script/public-inbox-init @@ -38,10 +38,11 @@ my $pi_config = PublicInbox::Config->default_file; my $dir = dirname($pi_config); mkpath($dir); # will croak on fatal errors my ($fh, $pi_config_tmp) = tempfile('pi-init-XXXXXXXX', DIR => $dir); +my $perm; if (-e $pi_config) { open(my $oh, '<', $pi_config) or die "unable to read $pi_config: $!\n"; my @st = stat($oh); - my $perm = $st[2]; + $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"; @@ -125,6 +126,9 @@ if ($version >= 2) { die "Unsupported -V/--version: $version\n"; } +# needed for git prior to v2.1.0 +umask(0077) if defined $perm; + foreach my $addr (@address) { next if $seen{lc($addr)}; x(@x, "--add", "$pfx.address", $addr); @@ -136,5 +140,11 @@ if (defined($indexlevel)) { x(@x, "$pfx.indexlevel", $indexlevel); } +# needed for git prior to v2.1.0 +if (defined $perm) { + chmod($perm & 07777, $pi_config_tmp) or + die "(f)chmod failed on future $pi_config: $!\n"; +} + rename $pi_config_tmp, $pi_config or die "failed to rename `$pi_config_tmp' to `$pi_config': $!\n"; -- cgit v1.2.3-24-ge0c7