about summary refs log tree commit homepage
path: root/script/public-inbox-init
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-05-22 02:13:58 +0000
committerEric Wong <e@80x24.org>2019-05-22 02:14:25 +0000
commit22fca958a2a4d43d5ee4e006bfc046b72d76cae0 (patch)
tree2dba60849d9e722b4f2e419fc4629b40ccf3d17a /script/public-inbox-init
parente220b8b2ee5cfd458167dc2c6c92726352c4c80e (diff)
downloadpublic-inbox-22fca958a2a4d43d5ee4e006bfc046b72d76cae0.tar.gz
"git config" did not preserve permissions of the config file it
modifies prior to git 2.1.0, so workaround that.
Diffstat (limited to 'script/public-inbox-init')
-rwxr-xr-xscript/public-inbox-init12
1 files changed, 11 insertions, 1 deletions
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";