update A later node teaches me that there is a perl module: SGI::FAM also works on linux. It needs you to have the fam library installed though.
update Here is some pure perl code interfacing to linux dnotify. Unfortunately there seems to be no way to get to the siginfo data. This example watches directory /tmp, but you can also watch an (existing) file. You'd probably do the real detecting of what changed not in the signal handler but after the pause(). I used a realtime signal to allow for signal queueing, but since you can't get to the siginfo information anyways (to get the fd on which there was a change), it probably makes sense to leave the signal on e.g. SIGIO, and just rescan all places you are watching.
After each change you can now try to detect to see if a new upload has finished. However, you'll need to keep this process running and probably will be doing multiple checks while the file is still in the process of being uploaded. So in the end it's not clear that you gained much over not using dnotify at all and just periodically check for a finished upload.#!/usr/bin/perl -w use strict; use POSIX qw(pause sigaction SA_SIGINFO); use constant { DN_ACCESS => 0x00000001, DN_MODIFY => 0x00000002, DN_CREATE => 0x00000004, DN_DELETE => 0x00000008, DN_RENAME => 0x00000010, DN_ATTRIB => 0x00000020, DN_MULTISHOT=> 0x80000000, F_SETSIG => 10, F_LINUX_SPECIFIC_BASE => 1024, SIGRTMIN => 32, SIGRTMAX => 64, }; use constant F_NOTIFY => F_LINUX_SPECIFIC_BASE+2; my $signum = SIGRTMIN+1; my $dir = "/tmp"; my $new_action = POSIX::SigAction->new(sub { print STDERR "Change in $dir"}); $new_action->safe(1); sigaction($signum, $new_action) || die "Could not sigaction signal $signum: $!"; open(my $fh, "<", "/tmp") || die "Could not open $dir: $!"; fcntl($fh, F_SETSIG, $signum) || die "Could not set IO signal to $signum for $dir: $!"; fcntl($fh, F_NOTIFY, DN_MODIFY|DN_CREATE|DN_DELETE|DN_MULTISHOT) || die "Could not set F_NOTIFY for $dir: $!"; pause while 1;
In reply to Re: auto detection of file upload on ftp server
by thospel
in thread auto detection of file upload on ftp server
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |