2 # Copyright 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;
5 use File::Basename qw(basename);
6 my $have_fast_inotify = eval { require Linux::Inotify2 } ||
7 eval { require IO::KQueue };
9 diag("$0 IO::KQueue or Linux::Inotify2 missing, test will be slow");
12 my ($ro_home, $cfg_path) = setup_public_inboxes;
13 my $x = "$ENV{HOME}/x";
14 my $y = "$ENV{HOME}/y";
15 lei_ok qw(add-external), "$ro_home/t1";
16 lei_ok qw(q mid:testmessage@example.com -o), $x;
17 lei_ok qw(q mid:testmessage@example.com -o), $y;
18 my @x = glob("$x/cur/*");
19 my @y = glob("$y/cur/*");
20 scalar(@x) == 1 or xbail 'expected 1 file', \@x;
21 scalar(@y) == 1 or xbail 'expected 1 file', \@y;
23 my $oid = '9bf1002c49eb075df47247b74d69bcd555e23422';
24 lei_ok qw(inspect), "blob:$oid";
25 my $ins = json_utf8->decode($lei_out);
26 my $exp = { "maildir:$x" => [ map { basename($_) } @x ],
27 "maildir:$y" => [ map { basename($_) } @y ] };
28 is_deeply($ins->{'mail-sync'}, $exp, 'inspect as expected');
29 lei_ok qw(add-watch), $x;
30 my $dst = $x[0] . 'S';
31 rename($x[0], $dst) or xbail "rename($x[0], $dst): $!";
35 tick; # wait for inotify or kevent
37 my @y2 = glob("$y/*/*");
38 is_deeply(\@y2, [ $ys ], "`seen' kw propagated to `y' dir");
39 lei_ok qw(note-event done);
40 lei_ok qw(inspect), "blob:$oid";
41 $ins = json_utf8->decode($lei_out);
42 $exp = { "maildir:$x" => [ map { basename($_) } glob("$x/*/*") ],
43 "maildir:$y" => [ map { basename($_) } glob("$y/*/*") ] };
44 is_deeply($ins->{'mail-sync'}, $exp, 'mail_sync matches FS');