2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 # Ensure KQNotify can pick up rename(2) and link(2) operations
6 # used by Maildir writing tools
9 use PublicInbox::TestCommon;
10 plan skip_all => 'KQNotify is only for *BSD systems' if $^O !~ /bsd/;
11 require_mods('IO::KQueue');
12 use_ok 'PublicInbox::KQNotify';
13 my ($tmpdir, $for_destroy) = tmpdir();
14 mkdir "$tmpdir/new" or BAIL_OUT "mkdir: $!";
15 open my $fh, '>', "$tmpdir/tst" or BAIL_OUT "open: $!";
16 close $fh or BAIL_OUT "close: $!";
18 my $kqn = PublicInbox::KQNotify->new;
19 my $mask = PublicInbox::KQNotify::MOVED_TO_OR_CREATE();
20 my $w = $kqn->watch("$tmpdir/new", $mask);
22 rename("$tmpdir/tst", "$tmpdir/new/tst") or BAIL_OUT "rename: $!";
23 my $hit = [ map { $_->fullname } $kqn->read ];
24 is_deeply($hit, ["$tmpdir/new/tst"], 'rename(2) detected (via NOTE_EXTEND)');
26 open $fh, '>', "$tmpdir/tst" or BAIL_OUT "open: $!";
27 close $fh or BAIL_OUT "close: $!";
28 link("$tmpdir/tst", "$tmpdir/new/link") or BAIL_OUT "link: $!";
29 $hit = [ grep m!/link$!, map { $_->fullname } $kqn->read ];
30 is_deeply($hit, ["$tmpdir/new/link"], 'link(2) detected (via NOTE_WRITE)');
33 link("$tmpdir/new/tst", "$tmpdir/new/link2") or BAIL_OUT "link: $!";
34 $hit = [ map { $_->fullname } $kqn->read ];
35 is_deeply($hit, [], 'link(2) not detected after cancel');