]> Sergey Matveev's repositories - public-inbox.git/commitdiff
init: preserve permissions for git prior to 2.1.0
authorEric Wong <e@80x24.org>
Wed, 22 May 2019 02:13:58 +0000 (02:13 +0000)
committerEric Wong <e@80x24.org>
Wed, 22 May 2019 02:14:25 +0000 (02:14 +0000)
"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

index 5516e798b61c3e0f3bd87fbfc0df19c3d6c97d0f..2cc704ce78f09970a34c80c67d52caf1abfecd46 100755 (executable)
@@ -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";