* [PATCH] hopefully fix broken permissions for search
@ 2015-08-23 19:43 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-08-23 19:43 UTC (permalink / raw)
To: meta
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-08-23 19:43 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:43 [PATCH] hopefully fix broken permissions for search 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).