2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 # Ensure FakeInotify can pick up rename(2) and link(2) operations
6 # used by Maildir writing tools
9 use PublicInbox::TestCommon;
10 use_ok 'PublicInbox::FakeInotify';
11 my $MIN_FS_TICK = 0.011; # for low-res CONFIG_HZ=100 systems
12 my ($tmpdir, $for_destroy) = tmpdir();
13 mkdir "$tmpdir/new" or BAIL_OUT "mkdir: $!";
14 open my $fh, '>', "$tmpdir/tst" or BAIL_OUT "open: $!";
15 close $fh or BAIL_OUT "close: $!";
17 my $fi = PublicInbox::FakeInotify->new;
18 my $mask = PublicInbox::FakeInotify::MOVED_TO_OR_CREATE();
20 my $cb = sub { push @$hit, map { $_->fullname } @_ };
21 my $w = $fi->watch("$tmpdir/new", $mask, $cb);
23 select undef, undef, undef, $MIN_FS_TICK;
24 rename("$tmpdir/tst", "$tmpdir/new/tst") or BAIL_OUT "rename: $!";
26 is_deeply($hit, ["$tmpdir/new/tst"], 'rename(2) detected');
29 select undef, undef, undef, $MIN_FS_TICK;
30 open $fh, '>', "$tmpdir/tst" or BAIL_OUT "open: $!";
31 close $fh or BAIL_OUT "close: $!";
32 link("$tmpdir/tst", "$tmpdir/new/link") or BAIL_OUT "link: $!";
34 is_deeply($hit, ["$tmpdir/new/link"], 'link(2) detected');
38 select undef, undef, undef, $MIN_FS_TICK;
39 link("$tmpdir/new/tst", "$tmpdir/new/link2") or BAIL_OUT "link: $!";
41 is_deeply($hit, [], 'link(2) not detected after cancel');
43 PublicInbox::DS->Reset;