|
@@ -83,12 +83,19 @@ foreach my $file (keys(%MON_FILES)) {
|
|
|
$tmp{'path'} = $file;
|
|
$tmp{'path'} = $file;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ # Record the directory name for folder monitoring
|
|
|
|
|
+ $tmp{'dir'} = dirname($tmp{'path'});
|
|
|
|
|
+
|
|
|
|
|
+ # Push a hash ref
|
|
|
$files{$file} = \%tmp;
|
|
$files{$file} = \%tmp;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# Loop forever
|
|
# Loop forever
|
|
|
while (1) {
|
|
while (1) {
|
|
|
|
|
|
|
|
|
|
+ # Reset the folder monitor state
|
|
|
|
|
+ my %folders = ();
|
|
|
|
|
+
|
|
|
# Provide a method to force updates even when the state does not change
|
|
# Provide a method to force updates even when the state does not change
|
|
|
my $update = 0;
|
|
my $update = 0;
|
|
|
|
|
|
|
@@ -165,6 +172,20 @@ while (1) {
|
|
|
|
|
|
|
|
# Check for the presence of a file
|
|
# Check for the presence of a file
|
|
|
if ($file->{'type'} =~ /^EXISTS/) {
|
|
if ($file->{'type'} =~ /^EXISTS/) {
|
|
|
|
|
+
|
|
|
|
|
+ # Use opendir/readdir before calling -e, to ensure fresh results
|
|
|
|
|
+ if (!$folders{ $file->{'dir'} }) {
|
|
|
|
|
+ my $dh = undef();
|
|
|
|
|
+ if (opendir($dh, $file->{'dir'})) {
|
|
|
|
|
+ if ($DEBUG) {
|
|
|
|
|
+ print STDERR 'Refreshed folder: ' . $file->{'dir'} . "\n";
|
|
|
|
|
+ }
|
|
|
|
|
+ my @files = readdir($dh);
|
|
|
|
|
+ closedir($dh);
|
|
|
|
|
+ }
|
|
|
|
|
+ $folders{ $file->{'dir'} } = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (-e $file->{'path'}) {
|
|
if (-e $file->{'path'}) {
|
|
|
$file->{'status'} = 1;
|
|
$file->{'status'} = 1;
|
|
|
}
|
|
}
|