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

Diff for /openbsd/OpenBSDTorrents/CurrentTorrents.pl between version 1.32 and 1.38

version 1.32, 2010/03/03 18:13:07 version 1.38, 2010/03/22 21:36:28
Line 1 
Line 1 
 #!/usr/bin/perl -T  #!/usr/bin/perl -T
 #$RedRiver: CurrentTorrents.pl,v 1.31 2010/02/26 22:58:20 andrew Exp $  #$RedRiver: CurrentTorrents.pl,v 1.37 2010/03/16 22:40:18 andrew Exp $
 use strict;  use strict;
 use warnings;  use warnings;
 use diagnostics;  use diagnostics;
Line 58 
Line 58 
             $name = $base;              $name = $base;
         }          }
   
         #print "Adding $_\n";          #print "Adding $DIR/$_\n";
   
         $files{$ext}{$name}{$epoch} = {          my $ct = {
             file => $_,              file => $_,
             dir  => $DIR,              dir  => $DIR,
             path => "$DIR/$_",              #path => "$DIR/$_",
             ext  => $ext,              ext  => $ext,
   
             #year      => $year,              #year      => $year,
Line 78 
Line 78 
         if ( $name =~ m/\A $OBT->{BASENAME} /xms          if ( $name =~ m/\A $OBT->{BASENAME} /xms
             && !exists $Possible_Torrents{$name} )              && !exists $Possible_Torrents{$name} )
         {          {
             #print "Would remove $_\n";              print "Would remove impossible $_\n";
             push @delete, $files{$ext}{$name}{$epoch};              push @delete, $ct;
           }
           else {
                   if ($files{$ext}{$name}{$epoch}) {
                       warn "Multiple torrents with $name and epoch $epoch\n";
                       push @delete, $files{$ext}{$name}{$epoch};
                   }
   
                   $files{$ext}{$name}{$epoch} = $ct;
         }          }
   
     }      }
     closedir DIR;      closedir DIR;
 }  }
Line 100 
Line 109 
   
 EPOCH: foreach my $epoch ( sort { $b <=> $a } keys %{$cn} ) {  EPOCH: foreach my $epoch ( sort { $b <=> $a } keys %{$cn} ) {
         my $ct = $cn->{$epoch};          my $ct = $cn->{$epoch};
         my $cf = $ct->{path};          my $cf = $ct->{dir} . '/' . $ct->{file};
   
         #print "\t$epoch - $cf\n";          #print "\t$epoch - $cf\n";
   
Line 136 
Line 145 
   
         if ( $seen{$name} && $seen{$name} ne $hash ) {          if ( $seen{$name} && $seen{$name} ne $hash ) {
             print "Removing older [$name] [$hash]\n\t",              print "Removing older [$name] [$hash]\n\t",
                 $ct->{path},                  $cf,
                 "\n";                  "\n";
             $ct->{reason} = 'older';              $ct->{reason} = 'older';
             push @delete, $ct;              push @delete, $ct;
Line 151 
Line 160 
             }              }
   
             print "Removing duplicate [$name] [$hash]\n\t",              print "Removing duplicate [$name] [$hash]\n\t",
                 $keep{$hash}{path}, "\n";                  $keep{$hash}{file}, "\n";
   
             $keep{$hash}{reason} = 'duplicate';              $keep{$hash}{reason} = 'duplicate';
             $ct->{reason} = 'duplicate';              $ct->{reason} = 'duplicate';
Line 194 
Line 203 
   
     my $name  = $keep{$hash}{name};      my $name  = $keep{$hash}{name};
     my $epoch = $keep{$hash}{epoch};      my $epoch = $keep{$hash}{epoch};
     my $reason = $keep{$hash}{reason};      my $reason = $keep{$hash}{reason} ? $keep{$hash}{reason} . q{ } : q{};
   
     #if ($reason && $reason ne 'only') {      #if ($reason && $reason ne 'only') {
     #    print "Keeping $reason instance of [$file] [$hash]\n",      #    print "Keeping $reason instance of [$file] [$hash]\n",
Line 207 
Line 216 
             or die "Couldn't rename '$file': $!";              or die "Couldn't rename '$file': $!";
   
         $dir = $OBT->{DIR_TORRENT};          $dir = $OBT->{DIR_TORRENT};
           $keep{$hash}{dir} = $dir;
   
         if ( exists $files{txt}{$name}{$epoch} ) {          if ( exists $files{txt}{$name}{$epoch} ) {
             my $m_file = $files{txt}{$name}{$epoch}{file};              my $m_file = $files{txt}{$name}{$epoch}{file};
             my $m_dir  = $files{txt}{$name}{$epoch}{dir};              my $m_dir  = $files{txt}{$name}{$epoch}{dir};
             rename( "$m_dir/$m_file", $OBT->{DIR_TORRENT} . "/" . $m_file )              rename( "$m_dir/$m_file", $OBT->{DIR_TORRENT} . "/" . $m_file )
                 or die "Couldn't rename '$m_file': $!";                  or die "Couldn't rename '$m_file': $!";
               $files{txt}{$name}{$epoch}{dir} = $OBT->{DIR_TORRENT};
         }          }
     }      }
   
     if ( !$seeding{$hash} ) {      if ( !$seeding{$hash} ) {
         print "Starting seed of [$file] [$hash]\n";          print 'Starting seed of ' . $reason . "[$file] [$hash]\n";
         if (!$client->add(          if (!$client->add(
                 filename     => "$dir/$file",                  filename     => "$dir/$file",
                 download_dir => $OBT->{DIR_FTP},                  download_dir => $OBT->{DIR_FTP},
Line 226 
Line 237 
         {          {
   
             #warn $client->error, ": $dir/$file\n";              #warn $client->error, ": $dir/$file\n";
             print "Removing invalid torrent\n\t", $keep{$hash}{path}, "\n";              print "Removing invalid torrent\n\t", $keep{$hash}{file}, "\n";
             push @delete, $keep{$hash};              push @delete, $keep{$hash};
         }          }
     }      }
 }  }
   
 foreach (@delete) {  foreach (@delete) {
     if ( $_->{path} ) {      my $path = $_->{dir} . '/' . $_->{file};
         print "Deleting '$_->{path}'\n";      if ( -e $path ) {
         unlink $_->{path} or die "Couldn't unlink $_->{path}";          print "Deleting '$path'\n";
           unlink $path or die "Couldn't delete $path";
         delete $files{torrent}{ $_->{name} }{ $_->{epoch} };          delete $files{torrent}{ $_->{name} }{ $_->{epoch} };
     }      }
     else {      else {
Line 247 
Line 259 
 foreach my $name ( keys %{ $files{ $OBT->{META_EXT} } } ) {  foreach my $name ( keys %{ $files{ $OBT->{META_EXT} } } ) {
     foreach my $epoch ( keys %{ $files{ $OBT->{META_EXT} }{$name} } ) {      foreach my $epoch ( keys %{ $files{ $OBT->{META_EXT} }{$name} } ) {
         unless ( exists $files{torrent}{$name}{$epoch} ) {          unless ( exists $files{torrent}{$name}{$epoch} ) {
             my $path = $files{ $OBT->{META_EXT} }{$name}{$epoch}{path};              my $path = $files{ $OBT->{META_EXT} }{$name}{$epoch}{dir}
                        . '/'
                        . $files{ $OBT->{META_EXT} }{$name}{$epoch}{file};
   
             print "Unlinking '$path'\n";              print "Unlinking '$path'\n";
             unlink $path or die "couldn't unlink '$path': $!";              unlink $path or die "couldn't unlink '$path': $!";
         }          }
Line 267 
Line 282 
         foreach my $file (@$files) {          foreach my $file (@$files) {
             if ( $file =~ /$INSTALL_ISO_REGEX/ ) {              if ( $file =~ /$INSTALL_ISO_REGEX/ ) {
                 Make_Possible("$dir/$file");                  Make_Possible("$dir/$file");
               }
               elsif ( $file =~ /$SONG_REGEX/xms ) {
                   Make_Possible("$dir/$1");
             }              }
         }          }
     }      }

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.38

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