--- a/bin/waitfordeb Thu Apr 19 20:53:29 2012 +0200
+++ b/bin/waitfordeb Thu Apr 19 21:10:37 2012 +0200
@@ -11,7 +11,7 @@
my $to = 60;
my $inotify = new Linux::Inotify2
- or die "unable to create new inotify object: $!";
+ or die "unable to create new inotify object: $!";
$inotify->blocking(0);
my %size;
@@ -19,18 +19,22 @@
my $ME = basename $0;
-sub delay_exit { my $fn = shift; $exit_after = time + $to if $size{basename $fn}; }
-sub verify_size {
+sub delay_exit {
+ my $fn = shift;
+ $exit_after = time + $to if $size{ basename $fn};
+}
+
+sub verify_size {
my $fn = shift;
delay_exit $fn;
my $bn = basename $fn;
- my $s = -s $fn;
+ my $s = -s $fn;
delete $size{$bn} if defined $s and $s >= $size{$bn};
}
my $incoming = "$ENV{HOME}/incoming";
-my $nfiles = 0;
-my $c = "$incoming/$ARGV[0]";
+my $nfiles = 0;
+my $c = "$incoming/$ARGV[0]";
# first setup a file creation watch on the incoming directory (we cannot set
# watches on objects that dont exist yet); then *if* a file which is listed in
@@ -44,7 +48,10 @@
no warnings qw(syntax);
if (/^files:\s*$/i) { $skip = 0; next; }
next if $skip;
- unless (/^ ([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ \n]+) *$/) { $skip = 1; next; }
+ unless (/^ ([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ \n]+) *$/) {
+ $skip = 1;
+ next;
+ }
use warnings;
$size{$5} = $2;
$nfiles++;
@@ -52,8 +59,12 @@
close C;
warn "$ME: no files found in changes file.\n" unless $nfiles;
-$inotify->watch($incoming, IN_MODIFY, sub { my $e = shift; delay_exit $e->fullname; } ) or warn "Can't watch: $!";
-$inotify->watch($incoming, IN_CLOSE, sub { my $e = shift; verify_size $e->fullname; } ) or warn "Can't watch: $!";
+$inotify->watch($incoming, IN_MODIFY,
+ sub { my $e = shift; delay_exit $e->fullname; })
+ or warn "Can't watch: $!";
+$inotify->watch($incoming, IN_CLOSE,
+ sub { my $e = shift; verify_size $e->fullname; })
+ or warn "Can't watch: $!";
# do initial check on file in case its upload is already finished
verify_size "$incoming/$_" for keys %size;