]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LEI.pm
get rid of unnecessary bytes::length usage
[public-inbox.git] / lib / PublicInbox / LEI.pm
index 4d5c61fe62bb6560c984900da0376416615c25b6..28fe0c836d7a3e842217b9bfd3cf63ac8ece2bf8 100644 (file)
@@ -37,6 +37,7 @@ $GLP_PASS->configure(qw(gnu_getopt no_ignore_case auto_abbrev pass_through));
 
 our %PATH2CFG; # persistent for socket daemon
 our $MDIR2CFGPATH; # /path/to/maildir => { /path/to/config => [ ino watches ] }
+our %LIVE_SOCK; # "GLOB(0x....)" => $lei->{sock}
 
 # TBD: this is a documentation mechanism to show a subcommand
 # (may) pass options through to another command:
@@ -485,6 +486,12 @@ sub err ($;@) {
 
 sub qerr ($;@) { $_[0]->{opt}->{quiet} or err(shift, @_) }
 
+sub qfin { # show message on finalization (LeiFinmsg)
+       my ($lei, $msg) = @_;
+       return if $lei->{opt}->{quiet};
+       $lei->{fmsg} ? push(@{$lei->{fmsg}}, "$msg\n") : qerr($lei, $msg);
+}
+
 sub fail_handler ($;$$) {
        my ($lei, $code, $io) = @_;
        close($io) if $io; # needed to avoid warnings on SIGPIPE
@@ -565,6 +572,7 @@ sub _lei_atfork_child {
        $dir_idle->force_close if $dir_idle;
        %PATH2CFG = ();
        $MDIR2CFGPATH = {};
+       %LIVE_SOCK = ();
        eval 'no warnings; undef $PublicInbox::LeiNoteEvent::to_flush';
        undef $errors_log;
        $quit = \&CORE::exit;
@@ -1423,12 +1431,13 @@ sub refresh_watches {
                                ++$renames;
                        }
                        next if $watches->{$f}; # may be set to pause
+                       require PublicInbox::LeiWatch;
                        $watches->{$f} = PublicInbox::LeiWatch->new($f);
                        $seen{$f} = undef;
                        add_maildir_watch($cd, $cfg_f);
                }
        }
-       my $wait = $renames ? $sto->ipc_do('done') : undef;
+       $lei->sto_done_request if $renames;
        if ($old) { # cull old non-existent entries
                for my $url (keys %$old) {
                        next if exists $seen{$url};
@@ -1462,4 +1471,19 @@ sub lms { # read-only LeiMailSync
        $lse ? $lse->lms : undef;
 }
 
+sub sto_done_request { # only call this from lei-daemon process (not workers)
+       my ($lei, $sock) = @_;
+       if ($sock //= $lei->{sock}) {
+               $LIVE_SOCK{"$sock"} = $sock;
+               $lei->{sto}->ipc_do('done', "$sock"); # issue, async wait
+       } else { # forcibly wait
+               my $wait = $lei->{sto}->ipc_do('done');
+       }
+}
+
+sub sto_done_complete { # called in lei-daemon when LeiStore->done is complete
+       my ($sock_str) = @_;
+       delete $LIVE_SOCK{$sock_str}; # frees {sock} for waiting lei clients
+}
+
 1;