diff options
author | Eric Wong <e@80x24.org> | 2021-07-19 08:59:35 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-07-22 02:29:00 +0000 |
commit | 5b4fde37adefa37508d131dbe013353ef3345051 (patch) | |
tree | bfd68b4f1fedf94464776a5760a4dc531f1d097e /lib/PublicInbox/LeiSelfSocket.pm | |
parent | 7e1c18af5468c7708e28de759911ec5542d23c4b (diff) | |
download | public-inbox-5b4fde37adefa37508d131dbe013353ef3345051.tar.gz |
This allows lei to automatically note keyword (message flag) changes made to a Maildir and propagate it into lei/store: lei add-watch --state=tag-ro /path/to/Maildir This doesn't persist across restarts, yet. In the future, it will be applied automatically to "lei q" output Maildirs by default (with an option to disable it). State values of tag-rw, index-<ro|rw>, import-<ro|rw> will all be supported for Maildir. This represents a fairly major internal change that's fairly intrusive, but the whole daemon-oriented design was to facilitate being able to automatically monitor (and propagate) Maildir/IMAP flag changes.
Diffstat (limited to 'lib/PublicInbox/LeiSelfSocket.pm')
-rw-r--r-- | lib/PublicInbox/LeiSelfSocket.pm | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/PublicInbox/LeiSelfSocket.pm b/lib/PublicInbox/LeiSelfSocket.pm new file mode 100644 index 00000000..3d847649 --- /dev/null +++ b/lib/PublicInbox/LeiSelfSocket.pm @@ -0,0 +1,45 @@ +# Copyright all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> + +# dummy placeholder socket for internal lei commands. +# This receives what script/lei receives, but isn't connected +# to an interactive terminal so I'm not sure what to do with it... +package PublicInbox::LeiSelfSocket; +use strict; +use v5.10.1; +use parent qw(PublicInbox::DS); +use Data::Dumper; +$Data::Dumper::Useqq = 1; # should've been the Perl default :P +use PublicInbox::Syscall qw(EPOLLIN EPOLLET); +use PublicInbox::Spawn; +my $recv_cmd; + +sub new { + my ($cls, $r) = @_; + my $self = bless { sock => $r }, $cls; + $r->blocking(0); + no warnings 'once'; + $recv_cmd = $PublicInbox::LEI::recv_cmd; + $self->SUPER::new($r, EPOLLIN|EPOLLET); +} + +sub event_step { + my ($self) = @_; + while (1) { + my (@fds) = $recv_cmd->($self->{sock}, my $buf, 4096 * 33); + if (scalar(@fds) == 1 && !defined($fds[0])) { + return if $!{EAGAIN}; + next if $!{EINTR}; + die "recvmsg: $!"; + } + # open so perl can auto-close them: + for my $fd (@fds) { + open(my $newfh, '+<&=', $fd) or die "open +<&=$fd: $!"; + } + return $self->close if $buf eq ''; + warn Dumper({ 'unexpected self msg' => $buf, fds => \@fds }); + # TODO: figure out what to do with these messages... + } +} + +1; |