[BACK]Return to NewTorrents.pl CVS log [TXT][DIR] Up to [local] / openbsd / OpenBSDTorrents

Diff for /openbsd/OpenBSDTorrents/NewTorrents.pl between version 1.1 and 1.10

version 1.1, 2005/03/24 05:28:08 version 1.10, 2006/07/24 19:03:53
Line 1 
Line 1 
 #!/usr/bin/perl -T  #!/usr/bin/perl -T
 #$Id$  #$RedRiver: NewTorrents.pl,v 1.9 2006/05/15 18:47:04 andrew Exp $
 use strict;  use strict;
 use warnings;  use warnings;
 use diagnostics;  use diagnostics;
Line 7 
Line 7 
 use lib 'lib';  use lib 'lib';
 use OpenBSDTorrents;  use OpenBSDTorrents;
   
   use POSIX qw / setsid :sys_wait_h /;
   $SIG{CHLD} = \&REAPER;
   my %Kids;
   my %Kid_Status;
   my %Need_Update;
   
 %ENV = ();  %ENV = ();
   
 use YAML;  use YAML;
   
   
 my $last_dir = '';  my $last_dir = '';
 while (<>) {  while (<>) {
         chomp;          chomp;
         if (my ($year,  $mon,  $mday,   $time,               $pid,   $oper, $file, $size) =          print $_, "\n";
             m#^(\d{4})/(\d{2})/(\d{2}) (\d{2}:\d{2}:\d{2}) \[(\d+)\] (\S+) (.+) (\d+)$# ) {          if (my ($message, $file) = m#(.*)\s+\`([^']+)'#) {
                 #print "($year, $mon, $mday, $time, $pid, $oper, $file, $size)\n";                  next if $message eq 'Making directory';
                 my ($dir, $file) = $file =~ m#^(.*)/([^/]+)#;  
                 #print "$dir - $file\n";                  my $dir = '';
                   if ($file =~ m#^(.*)/([^/]+)#) {
                           ($dir, $file) = ($1, $2);
                   }
                   #print "$message - $dir - $file\n";
                 if ($last_dir && $last_dir ne $dir) {                  if ($last_dir && $last_dir ne $dir) {
                         # This actually needs to be a sub that forks off                          StartTorrent($last_dir);
                         # the generation of this, and the running of the update script.  
                         print "MakeTorrent.pl $BaseName/$dir\n";  
                 }                  }
                 $last_dir = $dir;                  $last_dir = $dir;
           }
   }
   
   # Regen just the new ones now
   sleep(1) while (keys %Kids > 0);
   StartTorrent($last_dir);
   
   # after the new ones are done, regen all, just to make sure
   sleep(1) while (keys %Kids > 0);
   StartTorrent('skip');
   
   sub REAPER {
           my $child;
           while (($child = waitpid(-1,WNOHANG)) > 0) {
                   $Kid_Status{$child} = $?;
                   delete $Kids{$child};
           }
           $SIG{CHLD} = \&REAPER;  # still loathe sysV
   }
   
   sub StartTorrent
   {
           my $dir = shift;
           return undef unless $dir;
   
           my $should_fork = 1;
   
           if ($dir eq 'skip') {
                   #$dir = '';
                   %Need_Update = ();
                   $should_fork = 0;
         } else {          } else {
                 #print $_;                  $dir = $OBT->{BASENAME} . "/$dir";
                   $Need_Update{$dir} = 1;
         }          }
   
           if (keys %Kids > 0) {
                   print "Not making torrents for $dir now, already running\n";
                   return undef;
           }
   
           my @now_update = keys %Need_Update;
           %Need_Update = ();
   
           if ($should_fork) {
                   defined(my $pid = fork) or die "Can't fork: $!";
   
                   if ($pid) {
                           $Kids{$pid} = 1;
                           return undef;
                   }
   
           }
   
           if (@now_update) {
                   print "Making torrents for ", join(" ", @now_update), "\n";
           } else {
                   print "Remaking all torrents\n";
                   push @now_update, $dir;
           }
           exec($OBT->{DIR_HOME} . '/regen.sh', @now_update);
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.10

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>