=================================================================== RCS file: /cvs/openbsd/OpenBSDTorrents/NewTorrents.pl,v retrieving revision 1.10 retrieving revision 1.14 diff -u -r1.10 -r1.14 --- openbsd/OpenBSDTorrents/NewTorrents.pl 2006/07/24 19:03:53 1.10 +++ openbsd/OpenBSDTorrents/NewTorrents.pl 2009/10/20 20:03:25 1.14 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -#$RedRiver: NewTorrents.pl,v 1.9 2006/05/15 18:47:04 andrew Exp $ +#$RedRiver: NewTorrents.pl,v 1.13 2007/11/02 02:35:07 andrew Exp $ use strict; use warnings; use diagnostics; @@ -15,21 +15,26 @@ %ENV = (); -use YAML; - - my $last_dir = ''; while (<>) { + #print; chomp; - print $_, "\n"; - if (my ($message, $file) = m#(.*)\s+\`([^']+)'#) { - next if $message eq 'Making directory'; + # *** This requires --log-format="%t [%p] %o %f %l" on the rsync command + if (my ($year, $mon, $mday, $time, + $pid, $oper, $file, $size) = m#^ + (\d{4})/(\d{2})/(\d{2}) \s (\d{2}:\d{2}:\d{2}) \s + \[(\d+)\] \s (\S+) \s (.+) \s (\d+) + $#xms) { - my $dir = ''; - if ($file =~ m#^(.*)/([^/]+)#) { - ($dir, $file) = ($1, $2); - } - #print "$message - $dir - $file\n"; + $file =~ s/^.*$OBT->{BASENAME}\/?//; + + my ($dir, $file) = $file =~ m#^(.*)/([^/]+)#; + #print "$oper - ($last_dir) [$dir]/[$file]\n"; + + next unless $oper eq 'recv'; + next unless $size; + next unless $dir; + if ($last_dir && $last_dir ne $dir) { StartTorrent($last_dir); } @@ -45,6 +50,9 @@ sleep(1) while (keys %Kids > 0); StartTorrent('skip'); +# and wait for it to finish +sleep(1) while (keys %Kids > 0); + sub REAPER { my $child; while (($child = waitpid(-1,WNOHANG)) > 0) { @@ -52,27 +60,37 @@ delete $Kids{$child}; } $SIG{CHLD} = \&REAPER; # still loathe sysV + + StartTorrent('waiting'); } sub StartTorrent { my $dir = shift; return undef unless $dir; - + my $should_fork = 1; if ($dir eq 'skip') { #$dir = ''; %Need_Update = (); $should_fork = 0; - } else { + } + elsif ($dir eq 'waiting') { + return if ! %Need_Update; + + my $count = scalar keys %Need_Update; + print "Need to make $count waiting torrents\n"; + } + else { + print "Need to make torrent for '$dir'\n"; $dir = $OBT->{BASENAME} . "/$dir"; $Need_Update{$dir} = 1; } if (keys %Kids > 0) { print "Not making torrents for $dir now, already running\n"; - return undef; + return; } my @now_update = keys %Need_Update; @@ -83,7 +101,7 @@ if ($pid) { $Kids{$pid} = 1; - return undef; + return; } } @@ -95,4 +113,5 @@ push @now_update, $dir; } exec($OBT->{DIR_HOME} . '/regen.sh', @now_update); + exit; }