dumping ground for random patches and texts
 help / color / mirror / Atom feed
* spew-more
@ 2015-08-23 19:37 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-08-23 19:37 UTC (permalink / raw)
  To: spew

diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 5664c38..fcf2669 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: %o umask %o\n", $perm, $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;
+	}
 }

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-08-23 19:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-23 19:37 spew-more Eric Wong

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).