1 #!/usr/bin/perl -- -*- mode: cperl -*-
5 rrr-server - watch a tree and update indexfiles
9 rrr-server [options] principalfile
17 my @opt = <<'=back' =~ /B<--(\S+)>/g;
21 Prints a brief message and exists.
31 After you have setup a tree watch it with inotify and keep it
32 uptodate. Depends on inotify which probably only exists on linux.
38 It is not declared as prerequisites of the F:R:M:Recent package
39 because there are so many ways to use the package so that server side
40 is considered optional.
47 use File
::Find
qw(find);
48 use lib
"/home/k/sources/rersyncrecent/lib";
49 use File
::Rsync
::Mirror
::Recent
;
52 use Pod
::Usage
qw(pod2usage);
53 use Time
::HiRes
qw(time);
68 my($principal) = @ARGV;
69 my $recc = File
::Rsync
::Mirror
::Recent
->new
70 (local => $principal);
71 my($rf) = $recc->principal_recentfile;
72 my $rootdir = $rf->localroot;
73 for my $req (qw(Linux::Inotify2 File::Find::Rule)) {
74 eval qq{ require $req; 1 };
76 die "Failing on 'require $req': $@"
82 my $inotify = new Linux
::Inotify2
83 or die "Unable to create new inotify object: $!";
85 foreach my $directory ( File
::Find
::Rule
->new->directory->in($rootdir) ) {
86 $inotify->watch( $directory, IN_MODIFY
()|IN_MOVED_FROM
()|IN_MOVED_TO
()|IN_CREATE
()|IN_DELETE
()|IN_DELETE_SELF
()|IN_MOVE_SELF
() )
87 or die "watch creation failed";
92 my $in_callback = sub {
95 for my $watch (qw(IN_MODIFY IN_MOVED_FROM IN_MOVED_TO IN_CREATE IN_DELETE IN_DELETE_SELF IN_MOVE_SELF)) {
96 push @stringifiedmask, $watch if $ev->$watch();
98 warn sprintf "%s %s %s %s %s %s", ++$i, time, $ev->w->name, $ev->name, $ev->fullname, join("|",@stringifiedmask);
102 my @events = $inotify->read;
103 unless ( @events > 0 ) {
104 print "read error: $!";
107 foreach my $event (@events) {
108 $in_callback->($event);
110 # no sleep necessary, read is blocking
119 # cperl-indent-level: 4