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

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

version 1.10, 2006/07/24 19:03:53 version 1.17, 2010/05/19 23:19:43
Line 1 
Line 1 
 #!/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.16 2010/03/08 20:19:37 andrew Exp $
 use strict;  use strict;
 use warnings;  use warnings;
 use diagnostics;  use diagnostics;
Line 15 
Line 15 
   
 %ENV = ();  %ENV = ();
   
 use YAML;  
   
   
 my $last_dir = '';  my $last_dir = '';
   my $last_file = '';
 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);
                 }                  }
                   elsif ($last_file && $last_file ne $file
                           && $last_file =~ /$INSTALL_ISO_REGEX/xms) {
                           StartTorrent("$dir/$file");
                   }
   
                 $last_dir = $dir;                  $last_dir = $dir;
                   $last_file = $file;
         }          }
 }  }
   
Line 45 
Line 57 
 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) {
Line 52 
Line 67 
                 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 "Have $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;
Line 83 
Line 108 
   
                 if ($pid) {                  if ($pid) {
                         $Kids{$pid} = 1;                          $Kids{$pid} = 1;
                         return undef;                          return;
                 }                  }
   
         }          }
   
           print "\n";
         if (@now_update) {          if (@now_update) {
                 print "Making torrents for ", join(" ", @now_update), "\n";                  print "Making torrents for ", join(" ", @now_update), "\n";
         } else {          } else {
Line 95 
Line 121 
                 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;
 }  }

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

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