user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] init: respect umask when creating description
Date: Tue,  2 Nov 2021 06:57:43 +0000	[thread overview]
Message-ID: <20211102065743.7509-1-e@80x24.org> (raw)

I noticed a description for a new inbox had st_mode=0600.
---
 script/public-inbox-init | 12 ++++++------
 t/init.t                 |  8 +++++++-
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/script/public-inbox-init b/script/public-inbox-init
index 1223d47e..5de45781 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -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): $!";
-}
diff --git a/t/init.t b/t/init.t
index 4bec6a2f..6f4c9dce 100644
--- 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;

                 reply	other threads:[~2021-11-02  6:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211102065743.7509-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    --subject='Re: [PATCH] init: respect umask when creating description' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).