]> Sergey Matveev's repositories - public-inbox.git/commitdiff
hopefully fix broken permissions for search
authorEric Wong <e@80x24.org>
Sun, 23 Aug 2015 19:41:28 +0000 (19:41 +0000)
committerEric Wong <e@80x24.org>
Sun, 23 Aug 2015 19:41:28 +0000 (19:41 +0000)
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
public-inbox-mda

index 5664c385017a621afb9bd5bd410974938d38f775..2c2f819399867f9d607e909d4ae42cc97092a4d1 100644 (file)
@@ -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,8 +287,13 @@ 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};
@@ -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;
index 8e98d6ebe2a89c901895be1836fd3c6d7c1a476c..c4822b6180e6124b84991bffbd25905dac857c4a 100755 (executable)
@@ -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;
        };
 }