about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rwxr-xr-xscript/public-inbox-init5
-rw-r--r--t/init.t10
2 files changed, 13 insertions, 2 deletions
diff --git a/script/public-inbox-init b/script/public-inbox-init
index 739ec9e5..e23d1419 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -28,6 +28,11 @@ mkpath($dir); # will croak on fatal errors
 my ($fh, $filename) = tempfile('pi-init-XXXXXXXX', DIR => $dir);
 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];
+        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";
         my $old;
         {
                 local $/;
diff --git a/t/init.t b/t/init.t
index b78fbaf5..f87dc225 100644
--- a/t/init.t
+++ b/t/init.t
@@ -13,10 +13,16 @@ use constant pi_init => 'blib/script/public-inbox-init';
         my $cfgfile = "$ENV{PI_DIR}/config";
         my @cmd = (pi_init, 'blist', "$tmpdir/blist",
                    qw(http://example.com/blist blist@example.com));
-        is(system(@cmd), 0, 'public-inbox-init failed');
+        is(system(@cmd), 0, 'public-inbox-init OK');
 
         ok(-e $cfgfile, "config exists, now");
-        is(system(@cmd), 0, 'public-inbox-init failed (idempotent)');
+        is(system(@cmd), 0, 'public-inbox-init OK (idempotent)');
+
+        chmod 0666, $cfgfile or die "chmod failed: $!";
+        @cmd = (pi_init, 'clist', "$tmpdir/clist",
+                   qw(http://example.com/clist clist@example.com));
+        is(system(@cmd), 0, 'public-inbox-init clist OK');
+        is((stat($cfgfile))[2] & 07777, 0666, "permissions preserved");
 }
 
 done_testing();