Skip to content
Open
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
29 changes: 17 additions & 12 deletions lib/Filesys/Notify/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,23 @@ sub _full_scan {
my %map;
for my $path (@paths) {
my $fp = eval { Cwd::realpath($path) } or next;
File::Find::finddepth({
wanted => sub {
my $fullname = $File::Find::fullname || File::Spec->rel2abs($File::Find::name);
$map{Cwd::realpath($File::Find::dir)}{$fullname} = _stat($fullname);
},
follow_fast => 1,
follow_skip => 2,
no_chdir => 1,
}, $path);

# remove root entry
delete $map{$fp}{$fp};
if ( -f $fp ) {
$map{$fp}{$fp} = _stat($fp);
}
else {
File::Find::finddepth({
wanted => sub {
my $fullname = $File::Find::fullname || File::Spec->rel2abs($File::Find::name);
$map{Cwd::realpath($File::Find::dir)}{$fullname} = _stat($fullname);
},
follow_fast => 1,
follow_skip => 2,
no_chdir => 1,
}, $path);

# remove root entry
delete $map{$fp}{$fp};
}
}

return \%map;
Expand Down
54 changes: 54 additions & 0 deletions t/plain_file_with_inotify2.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use strict;
use warnings;

use Filesys::Notify::Simple;
use Test::More;
use FindBin;

eval { require Linux::Inotify2 };

plan skip_all => 'Linux::Inotify2 is required to run this test' if $@;

my $test_file = "$FindBin::Bin/x/plain_file_for_inotify2.data";
open my $out, ">", $test_file;
print $out "foo" . time;
close $out;

my $w = Filesys::Notify::Simple->new( [$test_file] );

my $pid = fork;
if ( $pid == 0 ) {
sleep 3;

unlink $test_file;

my $other_file = "$FindBin::Bin/x/bar";
open $out, ">", $other_file;
print $out "bar" . time;
close $out;

unlink $other_file;

exit;
}
elsif ( $pid != 0 ) {
my $event;

local $SIG{ALRM} = sub { return };
alarm 10;

$w->wait( sub { $event = shift } );
like $event->{path}, qr/plain_file_for_inotify2/,
'first event is from watched file';

$w->wait( sub { $event = shift } );
is $event, undef, 'only one event';

waitpid $pid, 0;
}
else {
die $!;
}

done_testing();