Skip to content

Commit 8f5a9fc

Browse files
committed
Fix event emitting from empty directories
There was no event emitted if the last entry from a directory was removed. Keep track of all directories in a specific location (`.`) inside the fs hash.
1 parent 2f69378 commit 8f5a9fc

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

lib/Filesys/Notify/Simple.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ sub _full_scan {
201201
File::Find::finddepth({
202202
wanted => sub {
203203
my $fullname = $File::Find::fullname || File::Spec->rel2abs($File::Find::name);
204-
$map{Cwd::realpath($File::Find::dir)}{$fullname} = _stat($fullname);
204+
my $stat = $map{Cwd::realpath($File::Find::dir)}{$fullname} = _stat($fullname);
205+
$map{$path}{$fullname} = $stat if $stat->{is_dir}; # keep track of directories
205206
},
206207
follow_fast => 1,
207208
follow_skip => 2,

t/empty_dir.t

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
use strict;
2+
use Filesys::Notify::Simple;
3+
use Test::More;
4+
use Test::SharedFork;
5+
use File::Temp qw( tempdir );
6+
7+
use FindBin;
8+
9+
plan tests => 2;
10+
11+
my $dir = tempdir( DIR => "$FindBin::Bin/x" );
12+
my $w = Filesys::Notify::Simple->new([ "$dir" ]);
13+
14+
mkdir "$dir/root";
15+
16+
17+
my $pid = fork;
18+
if ($pid == 0) {
19+
Test::SharedFork->child;
20+
sleep 1;
21+
note "mkdir subroot\n";
22+
mkdir "$dir/subroot";
23+
# sleep 1;
24+
# note "mkdir subroot/deep\n";
25+
# mkdir "$dir/subroot/deep";
26+
# sleep 1;
27+
# note "mkdir subroot/deep/down\n";
28+
# mkdir "$dir/subroot/deep/down";
29+
# sleep 1;
30+
# note "rmdir subroot/deep/down\n";
31+
# rmdir "$dir/subroot/deep/down";
32+
# sleep 1;
33+
# note "rmdir subroot/deep\n";
34+
# rmdir "$dir/subroot/deep";
35+
sleep 1;
36+
note "rmdir subroot\n";
37+
rmdir "$dir/subroot";
38+
} elsif ($pid != 0) {
39+
Test::SharedFork->parent;
40+
my $event;
41+
alarm 10;
42+
note "wait mkdir subroot\n";
43+
$w->wait(sub { $event = shift });
44+
like $event->{path}, qr/subroot/;
45+
# alarm 10;
46+
# note "wait mkdir subroot/deep\n";
47+
# $w->wait(sub { $event = shift });
48+
# like $event->{path}, qr/subroot[\/\\]deep/;
49+
# alarm 10;
50+
# note "wait mkdir subroot/deep/down\n";
51+
# $w->wait(sub { $event = shift });
52+
# like $event->{path}, qr/subroot[\/\\]deep[\/\\]down/;
53+
# alarm 10;
54+
# note "wait rmdir subroot/deep/down\n";
55+
# $w->wait(sub { $event = shift });
56+
# like $event->{path}, qr/subroot[\/\\]deep[\/\\]down/;
57+
# alarm 10;
58+
# note "wait rmdir subroot/deep\n";
59+
# $w->wait(sub { $event = shift });
60+
# like $event->{path}, qr/subroot[\/\\]deep/;
61+
alarm 10;
62+
note "wait rmdir subroot\n";
63+
$w->wait(sub { $event = shift });
64+
like $event->{path}, qr/subroot/;
65+
waitpid $pid, 0;
66+
} else {
67+
die $!;
68+
}
69+
70+

0 commit comments

Comments
 (0)