Tinkster has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
Trying to add "watches" event-triggered. The idea is to have the files that eventually end up in the in-directories automatically processed, and have the results put into the out ones of the same 0-9{9} subdirs.
When I add a directory structure under the main dir in question, /home/tink/files/, the watch creation always fails; can someone think of a reason WHY?
The sub-directories are always 9-digit names, and always get created via
mkdir -p /home/tink/files/123456789/{in,out}The script is clumsy, and fraught w/ debug code atm.
#!/usr/bin/perl -w use Linux::Inotify2; use File::Find (); use strict; use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; sub wanted; my @results = '/home/tink/files/'; File::Find::find({wanted => \&wanted}, '/home/tink/files/'); print "@results\n"; sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -d _ && ( /^in\z/s || /^out\z/s ) && push(@results, $name); } our $inotify = new Linux::Inotify2 or die "unable to create new inotify object: $!"; my @result; foreach my $jail (@results){ $inotify->watch($jail, IN_CLOSE_WRITE|IN_CREATE|IN_DELETE) or die "w +atch creation failed" ; } while () { my @events = $inotify->read; unless (@events > 0) { print "read error: $!"; last ; } foreach (@events) { printf "mask\t%d\t\%s\t%s\n", $_->mask, $_->name, $_->fullname ; if ( $_->fullname =~ m@(/home/tink/files/[0-9]{9})@) { sleep 5; my $myin = "'".$1."/in'"; my $myout = "'".$1."/out'"; printf "%s\t%s\n", $myin ,$myout; $inotify->watch($myin, IN_CLOSE_WRITE|IN_CREATE|IN_DELETE) or d +ie "watch creation failed" ; $inotify->watch($myout, IN_CLOSE_WRITE|IN_CREATE|IN_DELETE) or +die "watch creation failed" ; } } }
Cheers, Tink
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Linux::Inotify2, adding sub-dirs to watches event-triggered...
by Marshall (Canon) on Nov 19, 2010 at 10:41 UTC | |
by viveksnv (Sexton) on Nov 19, 2010 at 11:09 UTC | |
by Marshall (Canon) on Nov 19, 2010 at 14:45 UTC | |
by Tinkster (Novice) on Nov 22, 2010 at 00:51 UTC |