From: Eric Wong <e@80x24.org>
Date: Wed, 30 May 2018 02:54:48 +0000 (+0000)
Subject: respect umask if core.sharedRepository is not set
X-Git-Tag: v1.2.0~503
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=6ca8f8d03fa8ee93edc8299f53d624f5d5841408;p=public-inbox.git

respect umask if core.sharedRepository is not set

This is consistent with git itself and the previous behavior
was a result of misunderstanding of how git interprets this.
And adjust tests slightly to match the new behavior.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
	<38873789-ab42-65a1-20c9-12c30b171f4f@linuxfoundation.org>
---

diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index 5c11a36c..9b0cdfd0 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -175,7 +175,7 @@ sub _read_git_config_perm {
 sub _git_config_perm {
 	my $self = shift;
 	my $perm = scalar @_ ? $_[0] : _read_git_config_perm($self);
-	return PERM_GROUP if (!defined($perm) || $perm eq '');
+	return PERM_UMASK if (!defined($perm) || $perm eq '');
 	return PERM_UMASK if ($perm eq 'umask');
 	return PERM_GROUP if ($perm eq 'group');
 	if ($perm =~ /\A(?:all|world|everybody)\z/) {
diff --git a/t/search.t b/t/search.t
index 9a90fd53..c971fe3c 100644
--- a/t/search.t
+++ b/t/search.t
@@ -11,7 +11,7 @@ my $tmpdir = tempdir('pi-search-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 my $git_dir = "$tmpdir/a.git";
 my ($root_id, $last_id);
 
-is(0, system(qw(git init -q --bare), $git_dir), "git init (main)");
+is(0, system(qw(git init --shared -q --bare), $git_dir), "git init (main)");
 eval { PublicInbox::Search->new($git_dir) };
 ok($@, "exception raised on non-existent DB");
 
@@ -422,11 +422,12 @@ $ibx->with_umask(sub {
 });
 
 foreach my $f ("$git_dir/public-inbox/msgmap.sqlite3",
+		"$git_dir/public-inbox",
 		glob("$git_dir/public-inbox/xapian*/"),
 		glob("$git_dir/public-inbox/xapian*/*")) {
 	my @st = stat($f);
 	my ($bn) = (split(m!/!, $f))[-1];
-	is($st[2] & 07777, -f _ ? 0660 : 0770,
+	is($st[2] & 07777, -f _ ? 0660 : 02770,
 		"sharedRepository respected for $bn");
 }
 
diff --git a/t/v2writable.t b/t/v2writable.t
index 00b08e03..9e3bb755 100644
--- a/t/v2writable.t
+++ b/t/v2writable.t
@@ -11,6 +11,7 @@ foreach my $mod (qw(DBD::SQLite Search::Xapian)) {
 	plan skip_all => "$mod missing for nntpd.t" if $@;
 }
 use_ok 'PublicInbox::V2Writable';
+umask 007;
 my $mainrepo = tempdir('pi-v2writable-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 my $ibx = {
 	mainrepo => $mainrepo,