Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back out Cygwin handling, add more compatibility notes for Win32 #30

Merged
merged 3 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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