Skip to content

Commit

Permalink
This might fix GH issue mvgrimes#11
Browse files Browse the repository at this point in the history
  • Loading branch information
ufobat committed Nov 28, 2017
1 parent d327ff0 commit c335290
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
7 changes: 6 additions & 1 deletion lib/AnyEvent/Filesys/Notify.pm
Expand Up @@ -58,7 +58,12 @@ sub _process_events {
# Some backends need to add files (KQueue) or directories (Inotify2) to the
# watch list after they are created. Give them a chance to do that here.
$self->_process_events_for_backend(@events)
if $self->can('_process_events_for_backend');
if $self->can('_process_events_for_backend');

# inotify now scanns the direcoys as well
if ( $self->parse_events and $self->can('_parse_events_postprocess') ) {
@events = $self->_parse_events_postprocess(@events);
}

$self->cb->(@events) if @events;

Expand Down
47 changes: 37 additions & 10 deletions lib/AnyEvent/Filesys/Notify/Role/Inotify2.pm
Expand Up @@ -80,23 +80,50 @@ sub _parse_events {
# New directories are not automatically watched, we will add it to the
# list of watched directories in `around '_process_events'` but in
# the meantime, we will miss any newly created files in the subdir
if ( $e->IN_ISDIR and $type eq 'created' ) {
}

return @events;
}

sub _parse_events_postprocess {
my ( $self, @events ) = @_;

my %additional;
foreach my $e (@events) {
if ( $e->is_dir and $e->type eq 'created' ) {
my $rule = Path::Iterator::Rule->new;
my $next = $rule->iter( $e->fullname );
my $next = $rule->iter( $e->path );
while ( my $file = $next->() ) {
next if $file eq $e->fullname;
push @events,
AnyEvent::Filesys::Notify::Event->new(
path => $file,
type => 'created',
is_dir => -d $file,
);
next if $file eq $e->path;
my $is_dir = -d $file;
$additional{$file}{created} =
AnyEvent::Filesys::Notify::Event->new(
path => $file,
type => 'created',
is_dir => $is_dir,
);

# if you would regually write to this file you would also see the modify event!
# on Inotify you always see the modified as well.
$additional{$file}{modified} =
AnyEvent::Filesys::Notify::Event->new(
path => $file,
type => 'modified',
is_dir => $is_dir,
);
}

}
}
# deduplicate
foreach my $e (@events) {
my $path = $e->path;

return @events;
if (exists $additional{$e->path}{$e->type}) {
$additional{$e->path}{$e->type} = undef;
}
}
return @events, grep { defined $_} map { ($_->{modified}, $_->{created}) } values %additional;
}

# Need to add newly created sub-dirs to the watch list.
Expand Down

0 comments on commit c335290

Please sign in to comment.