| version 1.10, 2006/07/24 19:03:53 |
version 1.14, 2009/10/20 20:03:25 |
|
|
| #!/usr/bin/perl -T |
#!/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 strict; |
| use warnings; |
use warnings; |
| use diagnostics; |
use diagnostics; |
|
|
| |
|
| %ENV = (); |
%ENV = (); |
| |
|
| use YAML; |
|
| |
|
| |
|
| my $last_dir = ''; |
my $last_dir = ''; |
| while (<>) { |
while (<>) { |
| |
#print; |
| chomp; |
chomp; |
| print $_, "\n"; |
# *** This requires --log-format="%t [%p] %o %f %l" on the rsync command |
| if (my ($message, $file) = m#(.*)\s+\`([^']+)'#) { |
if (my ($year, $mon, $mday, $time, |
| next if $message eq 'Making directory'; |
$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 = ''; |
$file =~ s/^.*$OBT->{BASENAME}\/?//; |
| if ($file =~ m#^(.*)/([^/]+)#) { |
|
| ($dir, $file) = ($1, $2); |
my ($dir, $file) = $file =~ m#^(.*)/([^/]+)#; |
| } |
#print "$oper - ($last_dir) [$dir]/[$file]\n"; |
| #print "$message - $dir - $file\n"; |
|
| |
next unless $oper eq 'recv'; |
| |
next unless $size; |
| |
next unless $dir; |
| |
|
| if ($last_dir && $last_dir ne $dir) { |
if ($last_dir && $last_dir ne $dir) { |
| StartTorrent($last_dir); |
StartTorrent($last_dir); |
| } |
} |
|
|
| sleep(1) while (keys %Kids > 0); |
sleep(1) while (keys %Kids > 0); |
| StartTorrent('skip'); |
StartTorrent('skip'); |
| |
|
| |
# and wait for it to finish |
| |
sleep(1) while (keys %Kids > 0); |
| |
|
| sub REAPER { |
sub REAPER { |
| my $child; |
my $child; |
| while (($child = waitpid(-1,WNOHANG)) > 0) { |
while (($child = waitpid(-1,WNOHANG)) > 0) { |
|
|
| delete $Kids{$child}; |
delete $Kids{$child}; |
| } |
} |
| $SIG{CHLD} = \&REAPER; # still loathe sysV |
$SIG{CHLD} = \&REAPER; # still loathe sysV |
| |
|
| |
StartTorrent('waiting'); |
| } |
} |
| |
|
| sub StartTorrent |
sub StartTorrent |
| { |
{ |
| my $dir = shift; |
my $dir = shift; |
| return undef unless $dir; |
return undef unless $dir; |
| |
|
| my $should_fork = 1; |
my $should_fork = 1; |
| |
|
| if ($dir eq 'skip') { |
if ($dir eq 'skip') { |
| #$dir = ''; |
#$dir = ''; |
| %Need_Update = (); |
%Need_Update = (); |
| $should_fork = 0; |
$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"; |
$dir = $OBT->{BASENAME} . "/$dir"; |
| $Need_Update{$dir} = 1; |
$Need_Update{$dir} = 1; |
| } |
} |
| |
|
| if (keys %Kids > 0) { |
if (keys %Kids > 0) { |
| print "Not making torrents for $dir now, already running\n"; |
print "Not making torrents for $dir now, already running\n"; |
| return undef; |
return; |
| } |
} |
| |
|
| my @now_update = keys %Need_Update; |
my @now_update = keys %Need_Update; |
|
|
| |
|
| if ($pid) { |
if ($pid) { |
| $Kids{$pid} = 1; |
$Kids{$pid} = 1; |
| return undef; |
return; |
| } |
} |
| |
|
| } |
} |
|
|
| push @now_update, $dir; |
push @now_update, $dir; |
| } |
} |
| exec($OBT->{DIR_HOME} . '/regen.sh', @now_update); |
exec($OBT->{DIR_HOME} . '/regen.sh', @now_update); |
| |
exit; |
| } |
} |