miyagawa/Filesys-Notify-Simple — Issue #9: Doesn't pickup changes in newly created directories with Linux::Inotify2
Author: cnmota
Created: 2012-02-02 18:25:02+00:00
State: open

This was an open bug that was on cpan and that I bumped into using the module, think this will fix it:

sub wait_inotify2 {
my @path = @_;

Linux::Inotify2->import;
my $inotify = Linux::Inotify2->new;

my $fs = _full_scan(@path);
for my $path (keys %$fs) {
$inotify->watch($path,&IN_MODIFY|&IN_CREATE|&IN_DELETE|&IN_DELETE_SELF|&IN_MOVE_SELF);
}

return sub {
my $cb = shift;
$inotify->blocking(1);
my @events = $inotify->read;

for (@events) {
if (-d $_->fullname && $_->IN_CREATE) {
$inotify->watch($_->fullname,&IN_MODIFY|&IN_CREATE|&IN_DELETE|&IN_DELETE_SELF|&IN_MOVE_SELF);
}
}

$cb->(map { +{ path => $_->fullname } } @events);
};
}