From 79e274b293a71fb41dd8bf6e9598a8e8a24fed4f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 14 May 2021 20:14:47 +0000 Subject: dir_idle: support IN_DELETE_SELF|IN_MOVE_SELF, too We'll treat IN_MOVE_SELF as IN_DELETE_SELF since there doesn't seem to be a reliable way to distinguish them with FakeInotify, nor know the new name with kevent. --- t/dir_idle.t | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 't') diff --git a/t/dir_idle.t b/t/dir_idle.t index 969c16e9..0bb3b758 100644 --- a/t/dir_idle.t +++ b/t/dir_idle.t @@ -6,10 +6,10 @@ use PublicInbox::DS qw(now); use File::Path qw(make_path); use_ok 'PublicInbox::DirIdle'; my ($tmpdir, $for_destroy) = tmpdir(); -make_path("$tmpdir/a/b"); +make_path("$tmpdir/a/b", "$tmpdir/c"); my @x; my $cb = sub { push @x, \@_ }; -my $di = PublicInbox::DirIdle->new(["$tmpdir/a"], $cb, 1); +my $di = PublicInbox::DirIdle->new(["$tmpdir/a", "$tmpdir/c"], $cb, 1); PublicInbox::DS->SetLoopTimeout(1000); my $end = 3 + now; PublicInbox::DS->SetPostLoopCallback(sub { scalar(@x) == 0 && now < $end }); @@ -17,6 +17,27 @@ tick(0.011); rmdir("$tmpdir/a/b") or xbail "rmdir $!"; PublicInbox::DS->EventLoop; is(scalar(@x), 1, 'got an event') and - is($x[0]->[0]->fullname, "$tmpdir/a/b", 'got expected fullname'); + is($x[0]->[0]->fullname, "$tmpdir/a/b", 'got expected fullname') and + ok($x[0]->[0]->IN_DELETE, 'IN_DELETE set'); + +tick(0.011); +rmdir("$tmpdir/a") or xbail "rmdir $!"; +@x = (); +$end = 3 + now; +PublicInbox::DS->EventLoop; +is(scalar(@x), 1, 'got an event') and + is($x[0]->[0]->fullname, "$tmpdir/a", 'got expected fullname') and + ok($x[0]->[0]->IN_DELETE_SELF, 'IN_DELETE_SELF set'); + +tick(0.011); +rename("$tmpdir/c", "$tmpdir/j") or xbail "rmdir $!"; +@x = (); +$end = 3 + now; +PublicInbox::DS->EventLoop; +is(scalar(@x), 1, 'got an event') and + is($x[0]->[0]->fullname, "$tmpdir/c", 'got expected fullname') and + ok($x[0]->[0]->IN_DELETE_SELF || $x[0]->[0]->IN_MOVE_SELF, + 'IN_DELETE_SELF set on move'); + PublicInbox::DS->Reset; done_testing; -- cgit v1.2.3-24-ge0c7