For Programmers: Free Programming Magazines  


Home > Archive > PERL POE > June 2005 > Problem with POE::Component::DirWatch









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem with POE::Component::DirWatch
David Good

2005-06-08, 9:04 pm

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
[test@foo ~]$

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com