Skip to content

Commit

Permalink
Merge pull request #30 from Corion/win32-readdirectorychanges
Browse files Browse the repository at this point in the history
Back out Cygwin handling, add more compatibility notes for Win32
  • Loading branch information
miyagawa authored Oct 3, 2022
2 parents 8d80e5a + 3f47eed commit dfbc2e0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
META.yml
Makefile
inc/
/blib/
/t/x
pm_to_blib
*~
MYMETA.*
/Filesys-Notify-Simple-*
/.build
!META.json
!META.json
48 changes: 32 additions & 16 deletions lib/Filesys/Notify/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ sub init {
} elsif (($^O eq 'freebsd' || $^O eq 'openbsd') && !NO_OPT && eval { require Filesys::Notify::KQueue; 1 }) {
$self->{watcher_cb} = \&wait_kqueue;
} elsif ($^O eq 'MSWin32' && !NO_OPT && eval { require Filesys::Notify::Win32::ReadDirectoryChanges; 1 }) {
$self->{watcher_cb} = mk_wait_win32_readdirectorychanges(0); # Not cygwin
} elsif ($^O eq 'cygwin' && !NO_OPT && eval { require Filesys::Notify::Win32::ReadDirectoryChanges; 1 }) {
$self->{watcher_cb} = mk_wait_win32_readdirectorychanges(1); # Cygwin
$self->{watcher_cb} = \&wait_win32_readdirectorychanges; # Not cygwin
} elsif ($^O eq 'MSWin32' && !NO_OPT && eval { require Win32::ChangeNotify; 1 }) {
$self->{watcher_cb} = mk_wait_win32(0); # Not cygwin
} elsif ($^O eq 'cygwin' && !NO_OPT && eval { require Win32::ChangeNotify; 1 }) {
Expand Down Expand Up @@ -154,21 +152,17 @@ sub mk_wait_win32 {
}
}

sub mk_wait_win32_readdirectorychanges {
my ($is_cygwin) = @_;
sub wait_win32_readdirectorychanges {
my @path = @_;
my $watcher = Filesys::Notify::Win32::ReadDirectoryChanges->new();
for my $dir (@path) {
$watcher->watch_directory( path => $dir, subtree => 1 );
};

return sub {
my @path = @_;
my $watcher = Filesys::Notify::Win32::ReadDirectoryChanges->new();
for my $dir (@path) {
$watcher->watch_directory( path => $dir, subtree => 1 );
};

return sub {
my $cb = shift;
my @events = $watcher->queue->dequeue;
$cb->(@events);
}
my $cb = shift;
my @events = $watcher->queue->dequeue;
$cb->(@events);
}
}

Expand Down Expand Up @@ -301,6 +295,28 @@ L<Mac::FSEvents>, L<Filesys::Notify::KQueue>,
L<Filesys::Notify::Win32::ReadDirectoryChanges> and L<Win32::ChangeNotify>
are truely optional.
NOTE: Using L<Filesys::Notify::Win32::ReadDirectoryChanges> has the following
limitations:
=over 4
=item *
The module only works with a Perl with threads and launches a thread for each
watched directory.
=item *
The module handles Unicode characters in filenames by converting them to
UTF-16le. If the characters are not representable in UTF-16le, the results are
undefined.
=item *
L<Filesys::Notify::Win32::ReadDirectoryChanges> does not yet support cygwin.
=back
NOTE: Using L<Win32::ChangeNotify> may put additional limitations.
=over 4
Expand Down

0 comments on commit dfbc2e0

Please sign in to comment.