I was messing around with POE::Component::DirWatch as a tool to take files
delivered via procmail to a maildir directory and move them to another
directory for later processing. Occasionally, my callback routine will
get the same filename twice -- even though the first time the file was
moved out of the directory! Here's a sample program that illustrates the
problem:
#!/usr/bin/perl
use strict;
use warnings;
use POE;
use POE::Component::DirWatch;
sub queue_file {
my ($file, $path) = @_[ARG0, ARG1];
print "$file\n";
rename($path, "testqueue/$file") or die "Can't rename $file: $!\n";
}
POE::Component::DirWatch->spawn(
Alias => 'dirwatch',
Directory => "incoming/new",
Filter => sub { -f $_[1] },
Callback => \&queue_file,
PollInterval => 5,
);
POE::Kernel->run();
exit;
When run, I'll see this:
[lots of lines trimmed]
1111433123.20087_0.foo
1111433123.20091_0.foo
1111433123.20095_0.foo
1111433124.20099_0.foo
1111433124.20099_0.foo
Can't rename 1111433124.20099_0.foo: No such file or directory
[EMAIL PROTECTED] ~]$