2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict; use v5.10.1; use PublicInbox::TestCommon;
7 my $stop_daemon = sub { # needed since we don't have inotify
9 chomp(my $pid = $lei_out);
10 $pid > 0 or xbail "bad pid: $pid";
11 kill('TERM', $pid) or xbail "kill: $!";
14 kill(0, $pid) or last;
16 kill(0, $pid) and xbail "daemon still running (PID:$pid)";
19 test_lei({ daemon_only => 1 }, sub {
20 my $d = "$ENV{HOME}/d";
21 my ($ro_home, $cfg_path) = setup_public_inboxes;
22 lei_ok qw(daemon-pid);
23 lei_ok qw(add-external), "$ro_home/t2";
24 lei_ok qw(q mid:testmessage@example.com -o), "Maildir:$d";
25 my (@o) = glob("$d/*/*");
26 scalar(@o) == 1 or xbail('multiple results', \@o);
27 my ($bn0) = ($o[0] =~ m!/([^/]+)\z!);
29 my $oid = '9bf1002c49eb075df47247b74d69bcd555e23422';
30 lei_ok 'inspect', "blob:$oid";
31 my $before = json_utf8->decode($lei_out);
32 my $exp0 = { 'mail-sync' => { "maildir:$d" => [ $bn0 ] } };
33 is_deeply($before, $exp0, 'inspect shows expected');
37 $dst =~ s/:2,.*\z// and $dst =~ s!/cur/!/new/! and
38 rename($o[0], $dst) or xbail "rename($o[0] => $dst): $!";
40 lei_ok 'inspect', "blob:$oid";
41 is_deeply(json_utf8->decode($lei_out),
42 $before, 'inspect unchanged immediately after restart');
43 lei_ok 'refresh-mail-sync', '--all';
44 lei_ok 'inspect', "blob:$oid";
45 my ($bn1) = ($dst =~ m!/([^/]+)\z!);
46 my $exp1 = { 'mail-sync' => { "maildir:$d" => [ $bn1 ] } };
47 is_deeply(json_utf8->decode($lei_out), $exp1,
48 'refresh-mail-sync updated location');
51 rename($dst, "$d/unwatched") or xbail "rename $dst out-of-the-way $!";
53 lei_ok 'refresh-mail-sync', $d;
54 lei_ok 'inspect', "blob:$oid";
55 is($lei_out, '{}', 'no known locations after "removal"');
56 lei_ok 'refresh-mail-sync', "Maildir:$d";
59 rename("$d/unwatched", $dst) or xbail "rename $dst back";
61 lei_ok 'refresh-mail-sync', "Maildir:$d";
62 lei_ok 'inspect', "blob:$oid";
63 is_deeply(json_utf8->decode($lei_out), $exp1,
64 'replaced file noted again');