about summary refs log tree commit homepage
path: root/lib/PublicInbox/WatchMaildir.pm
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-06-27 10:03:36 +0000
committerEric Wong <e@yhbt.net>2020-06-28 22:27:14 +0000
commitb2b1006759730507731fcd3fc3e0de68239e3b92 (patch)
treee29d5c29682b05a5d87b9db1452dda92bde6a0d2 /lib/PublicInbox/WatchMaildir.pm
parent5808636263d72b635a46100a7e7037074dad8f75 (diff)
downloadpublic-inbox-b2b1006759730507731fcd3fc3e0de68239e3b92.tar.gz
Since we already use inotify and EVFILT_VNODE (kqueue)
in -imapd, we might as well use them directly in -watch,
too.

This will allow public-inbox-watch to use PublicInbox::DS
for timers to watch newsgroups/mailboxes and have saner
signal handling in future commits.
Diffstat (limited to 'lib/PublicInbox/WatchMaildir.pm')
-rw-r--r--lib/PublicInbox/WatchMaildir.pm39
1 files changed, 19 insertions, 20 deletions
diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index fea7d5ef..22f19036 100644
--- a/lib/PublicInbox/WatchMaildir.pm
+++ b/lib/PublicInbox/WatchMaildir.pm
@@ -119,19 +119,6 @@ sub _done_for_now {
         }
 }
 
-sub _try_fsn_paths {
-        my ($self, $scan_re, $paths) = @_;
-        foreach (@$paths) {
-                my $path = $_->{path};
-                if ($path =~ $scan_re) {
-                        scan($self, $path);
-                } else {
-                        _try_path($self, $path);
-                }
-        }
-        _done_for_now($self);
-}
-
 sub remove_eml_i { # each_inbox callback
         my ($ibx, $arg) = @_;
         my ($self, $eml, $loc) = @$arg;
@@ -225,16 +212,28 @@ sub quit {
 
 sub watch_fs {
         my ($self) = @_;
+        require PublicInbox::DirIdle;
         my $scan = File::Temp->newdir("public-inbox-watch.$$.scan.XXXXXX",
                                         TMPDIR => 1);
         my $scandir = $self->{scandir} = $scan->dirname;
-        my $re = qr!\A$scandir/!;
-        my $cb = sub { _try_fsn_paths($self, $re, \@_) };
-
-        eval { require Filesys::Notify::Simple } or
-                die "Filesys::Notify::Simple is currently required for $0\n";
-        my $fsn = Filesys::Notify::Simple->new([@{$self->{mdir}}, $scandir]);
-        $fsn->wait($cb) until $self->{quit};
+        my $scan_re = qr!\A$scandir/!;
+        my $done = sub {
+                delete $self->{done_timer};
+                _done_for_now($self);
+        };
+        my $cb = sub {
+                my $path = $_[0]->fullname;
+                if ($path =~ $scan_re) {
+                        scan($self, $path);
+                } else {
+                        _try_path($self, $path);
+                }
+                $self->{done_timer} //= PublicInbox::DS::requeue($done);
+        };
+        my $di = PublicInbox::DirIdle->new([@{$self->{mdir}}, $scandir], $cb);
+        PublicInbox::DS->SetPostLoopCallback(sub { !$self->{quit} });
+        PublicInbox::DS->EventLoop;
+        _done_for_now($self);
 }
 
 # returns the git config section name, e.g [imap "imaps://user@example.com"]