Skip to content

Commit cddee23

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 24d4cad commit cddee23

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

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{$fullname}{$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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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([ "lib", "$dir" ]);
13+
14+
mkdir "$dir/root";
15+
16+
17+
my $pid = fork;
18+
if ($pid == 0) {
19+
Test::SharedFork->child;
20+
sleep 3;
21+
mkdir "$dir/subroot";
22+
sleep 3;
23+
rmdir "$dir/subroot";
24+
} elsif ($pid != 0) {
25+
Test::SharedFork->parent;
26+
my $event;
27+
for (1..2) {
28+
alarm 10;
29+
$w->wait(sub { $event = shift });
30+
like $event->{path}, qr/subroot/;
31+
}
32+
waitpid $pid, 0;
33+
} else {
34+
die $!;
35+
}
36+
37+

0 commit comments

Comments
 (0)