Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds new directories to watch *before* searching them for new entitie…
…s (GH#11) When using `parse_events => 1` with inotify, there is a race condition where entities in a new directory could be missed. We need to add the new directory to the watch list before searching it for new files or sub-directories. Reported by @ufobat in GitHub Issue #11. Thanks!
- Loading branch information
Showing
4 changed files
with
120 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use Test::More; | ||
|
||
# GitHub issue #11 | ||
# Previous implementation had a race condition which could miss entities | ||
# created inside a newly create directory. | ||
|
||
use strict; | ||
use warnings; | ||
use File::Spec; | ||
use lib 't/lib'; | ||
$|++; | ||
|
||
use TestSupport qw(create_test_files delete_test_files move_test_files | ||
modify_attrs_on_test_files $dir received_events receive_event); | ||
|
||
use AnyEvent::Filesys::Notify; | ||
use AnyEvent::Impl::Perl; | ||
|
||
create_test_files(qw(one/1 two/1)); | ||
## ls: one/1 two/1 | ||
|
||
my $n = AnyEvent::Filesys::Notify->new( | ||
dirs => [ map { File::Spec->catfile( $dir, $_ ) } qw(one two) ], | ||
filter => sub { shift !~ qr/ignoreme/ }, | ||
cb => sub { receive_event(@_) }, | ||
parse_events => 1, | ||
); | ||
isa_ok( $n, 'AnyEvent::Filesys::Notify' ); | ||
|
||
diag "This might take a few seconds to run..."; | ||
|
||
received_events( sub { create_test_files(qw(one/sub/2)) }, | ||
'create subdir and file', qw(created created) ); | ||
## ls: one/sub/1 one/sub/2 two/1 | ||
|
||
received_events( sub { create_test_files(qw(one/sub/ignoreme/1 one/sub/3)) }, | ||
'create subdir and file', qw(created) ); | ||
## ls: one/sub/1 one/sub/2 one/sub/ignoreme/1 one/sub/3 two/1 | ||
|
||
received_events( sub { create_test_files(qw(two/sub/ignoreme/sub/1)) }, | ||
'create subdir and file', qw(created) ); | ||
## ls: one/sub/1 one/sub/2 one/sub/ignoreme/1 one/sub/3 two/1 tow/sub/ignoreme/sub/1 | ||
|
||
## ok( 1, '... arrived' ); | ||
done_testing; |