Skip to content

_file_scan on Linux::Inotify2 wont monitor empty dirs #8

@cnmota

Description

@cnmota

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;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions