Subject: | _file_scan on Linux::Inotify2 wont monitor empty dirs |
If you declare a folder to watch that has empty subfolders those
subfolders will not be monitored since the _file_scan function is
discarding them.
I made a hack to fix this, don't know if it is good code, probably it
could be a lot better but I am not very familiar with File::Find, the
fix I did was:
sub _dir_empty {
my ($path) = @_;
return 0 unless -d $path;
opendir my($dir), $path;
my @content = grep {$_ !~ /^\.\.?$/} readdir $dir;
closedir($dir);
return scalar(@content) ? 0 : 1;
}
sub _full_scan {
my @path = @_;
require File::Find;
my %map;
for my $path (@path) {
my $fp = eval { Cwd::realpath($path) } or next;
File::Find::finddepth({
wanted => sub {
my $fullname = $File::Find::fullname ||
File::Spec->rel2abs($File::Find::name);
my $stat = _stat($fullname);
$map{Cwd::realpath($File::Find::dir)}{$fullname} =
_stat($fullname);
#FIX FOR EMPTY DIRS
if (_dir_empty($fullname)) {
$map{$fullname}{$fullname} = {};
}
},
follow_fast => 1,
follow_skip => 2,
no_chdir => 1,
}, @path);
# remove root entry
delete $map{$fp}{$fp};
}
return \%map;
}