Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the AnyEvent-Filesys-Notify CPAN distribution.

Report information
The Basics
Id: 115380
Status: resolved
Priority: 0/
Queue: AnyEvent-Filesys-Notify

People
Owner: Nobody in particular
Requestors: dave [...] jetcafe.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Possible Issue in deleting watched files
Date: Thu, 16 Jun 2016 16:00:22 -0700
To: bug-AnyEvent-Filesys-Notify [...] rt.cpan.org
From: Dave Hayes <dave [...] jetcafe.org>
Consider this small test script: use EV; use AnyEvent; use AnyEvent::Filesys::Notify; use AnyEvent::Filesys::Notify::Role::KQueue; mkdir("/tmp/foobar"); my $q_watcher = AnyEvent::Filesys::Notify->new( backend => 'KQueue', dirs => [ "/tmp/foobar"], cb => sub { foreach my $e (@_) { my $path = $e->path; my $type = $e->type; return unless ($type eq 'created' && -f $path); unlink($path); } }, ); EV::run; die "Shouldn't ever get here\n"; If I touch a file in /tmp/foobar (say "bletch") I get this error: EV: error in callback (ignoring): Can't open file (/tmp/foobar/bletch): No such file or directory at (eval 104) line 1. Is this an error in my understanding or in this module? :) Thanks in advance. -- Dave Hayes - Consultant - Altadena CA, USA - dave@jetcafe.org Show quoted text
>>>> *The opinions expressed above are entirely my own* <<<<
No one can make you feel inferior without your consent.
Subject: Re: [rt.cpan.org #115380] AutoReply: Possible Issue in deleting watched files
Date: Thu, 16 Jun 2016 19:53:30 -0700
To: bug-AnyEvent-Filesys-Notify [...] rt.cpan.org
From: Dave Hayes <dave [...] jetcafe.org>
Here's a weak fix to this issue, for your perusal and hopeful inclusion. I needed this to work, so I "subclassed" the role. I'm not sure that the around handler properly "subclasses", but this works to fix the issue just the same: package KQueueNoDie; use Moo::Role; use MooX::late; with "AnyEvent::Filesys::Notify::Role::KQueue"; # Work around a bug in the role above where deleted files can cause issues use namespace::autoclean; use AnyEvent; use IO::KQueue; use Carp; sub _init { my $self = shift; my $kqueue = IO::KQueue->new() or croak "Unable to create new IO::KQueue object"; $self->_fs_monitor($kqueue); # Need to add all the subdirs to the watch list, this will catch # modifications to files too. my $old_fs = $self->_old_fs; my @paths = keys %$old_fs; # Add each file and each directory my @fhs; for my $path (@paths) { my $fh = $self->_watch($path); push @fhs, $fh if (defined($fh)); } # Now use AE to watch the KQueue my $w; $w = AE::io $$kqueue, 0, sub { if ( my @events = $kqueue->kevent ) { $self->_process_events(@events); } }; $self->_watcher( { fhs => \@fhs, w => $w } ); $self->_check_filehandle_count; return 1; } around '_process_events' => sub { my ( $orig, $self, @e ) = @_; my $events = $self->$orig(@e); for my $event (@$events) { next unless $event->is_created; my $fh = $self->_watch( $event->path ); push @{ $self->_watcher->{fhs} }, $fh if (defined($fh)); } $self->_check_filehandle_count; return $events; }; sub _watch { my ( $self, $path ) = @_; open my $fh, '<', $path or do { warn "KQueue requires a filehandle for each watched file and directory.\n" . "You have exceeded the number of filehandles permitted by the OS.\n" if $! =~ /^Too many open files/; return if ($! =~ /no such file or directory/io); croak "Can't open file ($path): $!"; }; $self->_fs_monitor->EV_SET( fileno($fh), EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_LINK | NOTE_RENAME | NOTE_REVOKE, ); return $fh; } 1;
Dave, Thanks for the bug report and patch. I think the underlying problem is that the cb is called before the files are added to the watch. This would lead to different events depending on which backend is used. I'm releasing 1.20 which should address this.
Subject: Re: [rt.cpan.org #115380] Resolved: Possible Issue in deleting watched files
Date: Fri, 17 Jun 2016 14:19:18 -0700
To: bug-AnyEvent-Filesys-Notify [...] rt.cpan.org
From: Dave Hayes <dave [...] jetcafe.org>
Thank you -very- much for the quick turnaround. :) -- Dave Hayes - Consultant - Altadena CA, USA - dave@jetcafe.org Show quoted text
>>>> *The opinions expressed above are entirely my own* <<<<
Sleeping is to hunters as excitement is to students.