unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] hopefully fix broken permissions for search
Date: Sun, 23 Aug 2015 19:43:28 +0000	[thread overview]
Message-ID: <1440359008-26898-1-git-send-email-e@80x24.org> (raw)

We must preserve the umask for the entirety of the indexing
operation, as Xapian transactions replace entire files
atomically instead of writing them in place.
---
 lib/PublicInbox/SearchIdx.pm | 40 +++++++++++++++++++++++++++-------------
 public-inbox-mda             |  2 +-
 2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 5664c38..2c2f819 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -21,19 +21,18 @@ sub new {
 	my $dir = $class->xdir($git_dir);
 	require Search::Xapian::WritableDatabase;
 	my $flag = Search::Xapian::DB_OPEN;
-	if ($writable == 1) {
-		require File::Path;
-		File::Path::mkpath($dir);
-		$flag = Search::Xapian::DB_CREATE_OR_OPEN;
-	}
 	my $self = bless { git_dir => $git_dir }, $class;
-	my $umask = _umask_for($self->_git_config_perm);
-	my $old_umask = umask $umask;
-	my $db = eval { Search::Xapian::WritableDatabase->new($dir, $flag) };
-	my $err = $@;
-	umask $old_umask;
-	die $err if $err;
-	$self->{xdb} = $db;
+	my $perm = $self->_git_config_perm;
+	my $umask = _umask_for($perm);
+	$self->{umask} = $umask;
+	$self->{xdb} = $self->with_umask(sub {
+		if ($writable == 1) {
+			require File::Path;
+			File::Path::mkpath($dir);
+			$flag = Search::Xapian::DB_CREATE_OR_OPEN;
+		}
+		Search::Xapian::WritableDatabase->new($dir, $flag);
+	});
 	$self;
 }
 
@@ -288,9 +287,14 @@ sub do_cat_mail {
 	$@ ? undef : $mime;
 }
 
-# indexes all unindexed messages
 sub index_sync {
 	my ($self, $head) = @_;
+	$self->with_umask(sub { $self->_index_sync($head) });
+}
+
+# indexes all unindexed messages
+sub _index_sync {
+	my ($self, $head) = @_;
 	require PublicInbox::GitCatFile;
 	my $db = $self->{xdb};
 	my $hex = '[a-f0-9]';
@@ -423,4 +427,14 @@ sub _umask_for {
 	(~$rv & 0777);
 }
 
+sub with_umask {
+	my ($self, $cb) = @_;
+	my $old = umask $self->{umask};
+	my $rv = eval { $cb->() };
+	my $err = $@;
+	umask $old;
+	die $err if $@;
+	$rv;
+}
+
 1;
diff --git a/public-inbox-mda b/public-inbox-mda
index 8e98d6e..c4822b6 100755
--- a/public-inbox-mda
+++ b/public-inbox-mda
@@ -88,7 +88,7 @@ sub do_spamc {
 sub search_index_sync {
 	my ($git_dir) = @_;
 	eval {
-		require PublicInbox::Search;
+		require PublicInbox::SearchIdx;
 		PublicInbox::SearchIdx->new($git_dir, 2)->index_sync;
 	};
 }
-- 
EW


                 reply	other threads:[~2015-08-23 19:43 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=1440359008-26898-1-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).