Skip to content

Instantly share code, notes, and snippets.

@a2ikm
Created August 24, 2011 13:48
Show Gist options
  • Save a2ikm/1168107 to your computer and use it in GitHub Desktop.
Save a2ikm/1168107 to your computer and use it in GitHub Desktop.
rsync and Filesys::Notify::Simple are imcompatible
# [window1] start fsnotify.pl
$ cd ~/tmp
$ ... save fsnotify.pl here ...
$ perl fsnotify.pl [~ 22:39]
Watching tmp for file updates.
# [window2] rsync a file to the directory
$ rsync /somewhere/bar.txt ~/tmp
# [window1] fsnotify.pl detects some file in ~/tmp is updated
# but it's just a temporary file :-(
updated file is /home/myname/tmp/.bar.txt.yivwne
# it was filterd by valid_file,
# so `warn "-- $ev->{path} updated.\n";` wasn't executed
#!/usr/bin/env perl
use File::Basename
require Filesys::Notify::Simple;
my @watch = (dirname(__FILE__));
my $watcher = Filesys::Notify::Simple->new(\@watch);
warn "Watching @watch for file updates.\n";
sub valid_file {
my($file) = @_;
print "updated file is @{[$file->{path}]}\n";
$file->{path} !~ m![/\\][\._]|\.bak$|~$|_flymake\.p[lm]!;
}
while (1) {
my @restart;
# this is blocking
$watcher->wait(sub {
my @events = @_;
@events = grep valid_file($_), @events;
return unless @events;
@restart = @events;
});
next unless @restart;
for my $ev (@restart) {
warn "plackup will restart for @{[$ev->{path}]}\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment