# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use IO::Handle;
-use PublicInbox::WatchMaildir;
+use PublicInbox::Watch;
use PublicInbox::Config;
use PublicInbox::DS;
use PublicInbox::Sigfd;
my $oldset = PublicInbox::Sigfd::block_signals();
STDOUT->autoflush(1);
STDERR->autoflush(1);
-my ($config, $watch_md);
+local $0 = $0; # local since this script may be eval-ed
+my $watch = PublicInbox::Watch->new(PublicInbox::Config->new);
my $reload = sub {
- $config = PublicInbox::Config->new;
- $watch_md->quit if $watch_md;
- $watch_md = PublicInbox::WatchMaildir->new($config);
+ my $prev = $watch or return; # SIGQUIT issued
+ $watch->quit;
+ $watch = PublicInbox::Watch->new(PublicInbox::Config->new);
+ if ($watch) {
+ warn("I: reloaded\n");
+ } else {
+ warn("E: reloading failed\n");
+ $watch = $prev;
+ }
};
-$reload->();
-if ($watch_md) {
- my $scan = sub { $watch_md->trigger_scan('full') if $watch_md };
+
+if ($watch) {
+ my $scan = sub {
+ return if !$watch;
+ warn "I: scanning\n";
+ $watch->trigger_scan('full');
+ };
my $quit = sub {
- $watch_md->quit if $watch_md;
- $watch_md = undef;
+ $watch->quit if $watch;
+ $watch = undef;
+ $0 .= ' quitting';
};
my $sig = {
HUP => $reload,
PublicInbox::Sigfd::set_sigmask($oldset);
PublicInbox::DS->SetLoopTimeout(1000);
}
- $watch_md->watch($sig, $oldset) while ($watch_md);
+ $watch->watch($sig, $oldset) while ($watch);
}