]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LEI.pm
clone|--mirror: support --epoch=RANGE for partial clones
[public-inbox.git] / lib / PublicInbox / LEI.pm
index b468a32ca87d5b3cf6e25a95faaf05a370330157..9d5a5a46b3987fc05d4095fd31d751f37fa4c462 100644 (file)
@@ -206,7 +206,7 @@ our %CMD = ( # sorted in order of importance/use:
 
 'add-external' => [ 'LOCATION',
        'add/set priority of a publicinbox|extindex for extra matches',
-       qw(boost=i mirror=s inbox-version=i verbose|v+),
+       qw(boost=i mirror=s inbox-version=i epoch=s verbose|v+),
        @c_opt, index_opt(), @net_opt ],
 'ls-external' => [ '[FILTER]', 'list publicinbox|extindex locations',
        qw(format|f=s z|0 globoff|g invert-match|v local remote), @c_opt ],
@@ -278,7 +278,7 @@ our %CMD = ( # sorted in order of importance/use:
 'config' => [ '[...]', sub {
                'git-config(1) wrapper for '._config_path($_[0]);
        }, qw(config-file|system|global|file|f=s), # for conflict detection
-        qw(c=s@ C=s@), pass_through('git config') ],
+        qw(edit|e c=s@ C=s@), pass_through('git config') ],
 'inspect' => [ 'ITEMS...|--stdin', 'inspect lei/store and/or local external',
        qw(stdin| pretty ascii dir=s), @c_opt ],
 
@@ -420,7 +420,9 @@ my %OPTDESC = (
 'remote' => 'limit operations to those requiring network access',
 'remote!' => 'prevent operations requiring network access',
 
-'all:s up' => ['local|remote', 'update all remote or local saved searches' ],
+# up, refresh-mail-sync, export-kw
+'all:s' => ['TYPE|local|remote', 'all remote or local folders' ],
+
 'remote-fudge-time=s' => [ 'INTERVAL',
        'look for mail INTERVAL older than the last successful query' ],
 
@@ -870,14 +872,6 @@ sub _config {
        waitpid(spawn($cmd, \%env, \%rdr), 0);
 }
 
-sub lei_config {
-       my ($self, @argv) = @_;
-       $self->{opt}->{'config-file'} and return fail $self,
-               "config file switches not supported by `lei config'";
-       _config(@_);
-       x_it($self, $?) if $?;
-}
-
 sub lei_daemon_pid { puts shift, $$ }
 
 sub lei_daemon_kill {
@@ -1118,7 +1112,6 @@ sub dclose {
        my ($self) = @_;
        delete $self->{-progress};
        _drop_wq($self) if $self->{failed};
-       close(delete $self->{1}) if $self->{1}; # may reap_compress
        $self->close if $self->{-event_init_done}; # PublicInbox::DS::close
 }
 
@@ -1126,23 +1119,28 @@ sub dclose {
 sub event_step {
        my ($self) = @_;
        local %ENV = %{$self->{env}};
-       my $sock = $self->{sock};
        local $current_lei = $self;
        eval {
-               while (my @fds = $recv_cmd->($sock, my $buf, 4096)) {
+               my $buf;
+               while (my @fds = $recv_cmd->($self->{sock}, $buf, 4096)) {
                        if (scalar(@fds) == 1 && !defined($fds[0])) {
                                return if $! == EAGAIN;
                                next if $! == EINTR;
                                last if $! == ECONNRESET;
                                die "recvmsg: $!";
                        }
-                       for my $fd (@fds) {
-                               open my $rfh, '+<&=', $fd;
+                       for (@fds) { open my $rfh, '+<&=', $_ }
+               }
+               if ($buf eq '') {
+                       _drop_wq($self); # EOF, client disconnected
+                       dclose($self);
+               } elsif ($buf =~ /\A(STOP|CONT)\z/) {
+                       for my $wq (grep(defined, @$self{@WQ_KEYS})) {
+                               $wq->wq_kill($buf) or $wq->wq_kill_old($buf);
                        }
+               } else {
                        die "unrecognized client signal: $buf";
                }
-               _drop_wq($self); # EOF, client disconnected
-               dclose($self);
        };
        if (my $err = $@) {
                eval { $self->fail($err) };
@@ -1154,6 +1152,7 @@ sub event_step_init {
        my ($self) = @_;
        my $sock = $self->{sock} or return;
        $self->{-event_init_done} //= do { # persist til $ops done
+               $sock->blocking(0);
                $self->SUPER::new($sock, EPOLLIN|EPOLLET);
                $sock;
        };
@@ -1202,7 +1201,7 @@ sub dir_idle_handler ($) { # PublicInbox::DirIdle callback
                                $lei->dispatch('note-event',
                                                "maildir:$mdir", $nc, $bn, $fn);
                        };
-                       warn "E note-event $f: $@\n" if $@;
+                       warn "E: note-event $f: $@\n" if $@;
                }
        }
        if ($ev->can('cancel') && ($ev->IN_IGNORE || $ev->IN_UNMOUNT)) {
@@ -1227,6 +1226,7 @@ sub lazy_start {
        $errors_log = "$sock_dir/errors.log";
        my $addr = pack_sockaddr_un($path);
        my $lk = bless { lock_path => $errors_log }, 'PublicInbox::Lock';
+       umask(077) // die("umask(077): $!");
        $lk->lock_acquire;
        socket($listener, AF_UNIX, SOCK_SEQPACKET, 0) or die "socket: $!";
        if ($errno == ECONNREFUSED || $errno == ENOENT) {
@@ -1238,7 +1238,6 @@ sub lazy_start {
                $! = $errno; # allow interpolation to stringify in die
                die "connect($path): $!";
        }
-       umask(077) // die("umask(077): $!");
        bind($listener, $addr) or die "bind($path): $!";
        $lk->lock_release;
        undef $lk;
@@ -1387,7 +1386,7 @@ sub fchdir {
 sub wq_eof { # EOF callback for main daemon
        my ($lei) = @_;
        my $wq1 = delete $lei->{wq1} // return $lei->fail; # already failed
-       $wq1->wq_wait_old(\&wq_done_wait, $lei);
+       $wq1->wq_wait_old($wq1->can('_wq_done_wait') // \&wq_done_wait, $lei);
 }
 
 sub watch_state_ok ($) {
@@ -1504,4 +1503,12 @@ sub sto_done_request {
        $lei->err($@) if $@;
 }
 
+sub cfg_dump ($$) {
+       my ($lei, $f) = @_;
+       my $ret = eval { PublicInbox::Config->git_config_dump($f, $lei->{2}) };
+       return $ret if !$@;
+       $lei->err($@);
+       undef;
+}
+
 1;