Skip to content

Commit

Permalink
triggers modified_files on file deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Hernan Lopes committed Feb 4, 2024
1 parent 7a1cd71 commit 10cde32
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Mojo/Server/Morbo/Backend/Poll.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ use Mojo::File qw(path);
sub modified_files {
my $self = shift;

my $cache = $self->{cache} //= {};
my $cache = $self->{cache} //= {};
my $known_files = {map { $_ => 1 } keys %$cache};
my @files;
for my $file (map { -f $_ && -r _ ? $_ : _list($_) } @{$self->watch}) {
delete $known_files->{$file};
my ($size, $mtime) = (stat $file)[7, 9];
next unless defined $size and defined $mtime;
my $stats = $cache->{$file} ||= [$^T, $size];
next if $mtime <= $stats->[0] && $size == $stats->[1];
@$stats = ($mtime, $size);
push @files, $file;
}
for my $file (keys %$known_files) {

# any leftover file means they were deleted
push @files, $file;
delete $cache->{$file};
}
sleep $self->watch_timeout unless @files;

return \@files;
Expand Down

0 comments on commit 10cde32

Please sign in to comment.