dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: spew
Date: Sun, 23 Aug 2015 19:32:19 +0000	[thread overview]
Message-ID: <20150823193219.GA22263@dcvr.yhbt.net> (raw)

diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 5664c38..fdc4a6f 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -21,18 +21,21 @@ sub new {
 	my $dir = $class->xdir($git_dir);
 	require Search::Xapian::WritableDatabase;
 	my $flag = Search::Xapian::DB_OPEN;
+	my $self = bless { git_dir => $git_dir }, $class;
+	my $perm = $self->_git_config_perm;
+	my $umask = _umask_for($perm);
+	$self->{umask} = $umask;
+	open(my $fh, '>>', '/tmp/pi-err.log');
+	print $fh sprintf("perm: $perm umask %o\n", $umask);
+
 	if ($writable == 1) {
 		require File::Path;
-		File::Path::mkpath($dir);
+		$self->with_umask(sub { 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;
+	my $db = $self->with_umask(sub {
+		Search::Xapian::WritableDatabase->new($dir, $flag);
+	});
 	$self->{xdb} = $db;
 	$self;
 }
@@ -288,9 +291,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 +431,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..15ec890 100755
--- a/public-inbox-mda
+++ b/public-inbox-mda
@@ -88,7 +88,12 @@ 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;
 	};
+	if ($@) {
+		my $err = $@;
+		open(my $fh, '>>', '/tmp/pi-err.log');
+		print $fh $err;
+	}
 }

             reply	other threads:[~2015-08-23 19:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-23 19:32 Eric Wong [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-08-02 20:54 spew Eric Wong
2015-06-29 17:45 spew Eric Wong

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

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

  git send-email \
    --in-reply-to=20150823193219.GA22263@dcvr.yhbt.net \
    --to=e@80x24.org \
    --cc=spew@80x24.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).