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>
4 use v5.10.1; use strict; use PublicInbox::TestCommon;
5 use PublicInbox::DS qw(now);
6 use File::Path qw(make_path);
7 use_ok 'PublicInbox::DirIdle';
8 my ($tmpdir, $for_destroy) = tmpdir();
9 make_path("$tmpdir/a/b", "$tmpdir/c");
11 my $cb = sub { push @x, \@_ };
12 my $di = PublicInbox::DirIdle->new($cb);
13 $di->add_watches(["$tmpdir/a", "$tmpdir/c"], 1);
14 PublicInbox::DS->SetLoopTimeout(1000);
16 PublicInbox::DS->SetPostLoopCallback(sub { scalar(@x) == 0 && now < $end });
18 rmdir("$tmpdir/a/b") or xbail "rmdir $!";
19 PublicInbox::DS::event_loop();
20 is(scalar(@x), 1, 'got an event') and
21 is($x[0]->[0]->fullname, "$tmpdir/a/b", 'got expected fullname') and
22 ok($x[0]->[0]->IN_DELETE, 'IN_DELETE set');
25 rmdir("$tmpdir/a") or xbail "rmdir $!";
28 PublicInbox::DS::event_loop();
29 is(scalar(@x), 1, 'got an event') and
30 is($x[0]->[0]->fullname, "$tmpdir/a", 'got expected fullname') and
31 ok($x[0]->[0]->IN_DELETE_SELF, 'IN_DELETE_SELF set');
34 rename("$tmpdir/c", "$tmpdir/j") or xbail "rmdir $!";
37 PublicInbox::DS::event_loop();
38 is(scalar(@x), 1, 'got an event') and
39 is($x[0]->[0]->fullname, "$tmpdir/c", 'got expected fullname') and
40 ok($x[0]->[0]->IN_DELETE_SELF || $x[0]->[0]->IN_MOVE_SELF,
41 'IN_DELETE_SELF set on move');
43 PublicInbox::DS->Reset;