]> Sergey Matveev's repositories - public-inbox.git/commitdiff
init: respect umask when creating description
authorEric Wong <e@80x24.org>
Tue, 2 Nov 2021 06:57:43 +0000 (06:57 +0000)
committerEric Wong <e@80x24.org>
Tue, 2 Nov 2021 11:13:45 +0000 (11:13 +0000)
I noticed a description for a new inbox had st_mode=0600.

script/public-inbox-init
t/init.t

index 1223d47ef2c1e76f6c27163267d6fbcedae9cf15..5de4578158fb19412ade85ae534cab27fba1d4e6 100755 (executable)
@@ -212,6 +212,12 @@ if ($skip_docdata) {
 }
 $ibx->init_inbox(0, $skip_epoch, $skip_artnum);
 
+my $f = "$inboxdir/description";
+if (sysopen $fh, $f, O_CREAT|O_EXCL|O_WRONLY) {
+       print $fh "public inbox for $address[0]\n" or die "print($f): $!";
+       close $fh or die "close($f): $!";
+}
+
 # needed for git prior to v2.1.0
 umask(0077) if defined $perm;
 
@@ -248,9 +254,3 @@ if (defined $perm) {
 rename $pi_config_tmp, $pi_config or
        die "failed to rename `$pi_config_tmp' to `$pi_config': $!\n";
 undef $auto_unlink; # trigger ->DESTROY
-
-my $f = "$inboxdir/description";
-if (sysopen $fh, $f, O_CREAT|O_EXCL|O_WRONLY) {
-       print $fh "public inbox for $address[0]\n" or die "print($f): $!";
-       close $fh or die "close($f): $!";
-}
index 4bec6a2f31311a66e0ea5777440aec30c67b68e1..6f4c9dceeb33e60afcffe2f7ea242abc306add65 100644 (file)
--- a/t/init.t
+++ b/t/init.t
@@ -97,10 +97,16 @@ sub quiet_fail {
        $cmd = [ '-init', 'deep-non-existent', "$tmpdir/a/b/c/d",
                   qw(http://example.com/abcd abcd@example.com) ];
        $err = '';
+       my $umask = umask(022) // xbail "umask: $!";
        ok(run_script($cmd, $env, $rdr), 'initializes non-existent hierarchy');
+       umask($umask) // xbail "umask: $!";
        ok(-d "$tmpdir/a/b/c/d", 'directory created');
-       is(PublicInbox::Inbox::try_cat("$tmpdir/a/b/c/d/description"),
+       my $desc = "$tmpdir/a/b/c/d/description";
+       is(PublicInbox::Inbox::try_cat($desc),
                "public inbox for abcd\@example.com\n", 'description set');
+       my $mode = (stat($desc))[2];
+       is(sprintf('0%03o', $mode & 0777), '0644',
+               'description respects umask');
 
        open my $fh, '>', "$tmpdir/d" or BAIL_OUT "open: $!";
        close $fh;