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

Diff for /openbsd/OpenBSDTorrents/CurrentTorrents.pl between version 1.3 and 1.11

version 1.3, 2005/03/23 01:36:36 version 1.11, 2005/04/07 00:04:40
Line 14 
Line 14 
   
 #use YAML;  #use YAML;
   
   justme();
   
 my %files;  my %files;
 opendir DIR, $TorrentDir or die "Couldn't opendir $TorrentDir: $!";  opendir DIR, $OBT->{DIR_TORRENT}
           or die "Couldn't opendir $OBT->{DIR_TORRENT}: $!";
 foreach (readdir DIR) {  foreach (readdir DIR) {
         if (/^([^\/]+)$/) {          if (/^([^\/]+)$/) {
                 $_ = $1;                  $_ = $1;
Line 26 
Line 29 
         my ($name, $year, $mon, $mday, $hour, $min) =          my ($name, $year, $mon, $mday, $hour, $min) =
            /^(.*)-(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/;             /^(.*)-(\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/;
   
           $mon--;
         my $epoch = timegm(0,$min,$hour,$mday,$mon,$year);          my $epoch = timegm(0,$min,$hour,$mday,$mon,$year);
   
         my $t = BT::MetaInfo->new("$TorrentDir/$_");          #print "Adding $_\n";
         my $hash = $t->info_hash;  
         $hash = unpack("H*", $hash);  
   
         $files{$name}{$epoch} = {          $files{$name}{$epoch} = {
                 file      => $_,                  file      => $_,
                 comment   => $t->{comment},  
                 year      => $year,                  year      => $year,
                 mon       => $mon,                  mon       => $mon,
                 mday      => $mday,                  mday      => $mday,
                 hour      => $hour,                  hour      => $hour,
                 min       => $min,                  min       => $min,
                 epoch     => $epoch,                  epoch     => $epoch,
                 info_hash => $hash,  
         };          };
   
 }  }
 closedir DIR;  closedir DIR;
   
   
 my %keep;  my %keep;
 my @delete;  my @delete;
 foreach my $name (keys %files) {  foreach my $name (keys %files) {
         foreach my $time ( sort { $b <=> $a } keys %{ $files{$name} } ) {          #print "$name\n";
                 #print "$name - $time\n";  
                 my $hash = $files{$name}{$time}{info_hash};          foreach my $epoch ( sort { $b <=> $a } keys %{ $files{$name} } ) {
                   #print "\t$epoch\n";
                   my $torrent = $files{$name}{$epoch}{file};
   
                   my $t;
                   eval { $t = BT::MetaInfo->new($OBT->{DIR_TORRENT} . "/$torrent"); };
                   if ($@) {
                           warn "Error reading torrent $torrent\n";
                           next;
                   }
   
                   $files{$name}{$epoch}{comment}   = $t->{comment};
                   my ($path) = $t->{comment} =~ /Files from ([^\n]+)\n/s;
   
                   unless (-d $OBT->{DIR_FTP} . "/$path") {
                           #print "Deleting $files{$name}{$epoch}{file} the path doesn't exist.\n";
                           push @delete, $files{$name}{$epoch}{file};
                   }
   
                   if (keys %{ $files{$name} } == 1) {
                           #print "Skipping torrent for $name there is only one.\n";
                           next;
                   }
   
                   my $hash = $t->info_hash;
                   $hash = unpack("H*", $hash);
   
                   $files{$name}{$epoch}{info_hash} = $hash;
   
                   undef $t;
   
                 if (exists $keep{$name}) {                  if (exists $keep{$name}) {
                         if (exists $keep{$name}{$hash}) {                          if (exists $keep{$name}{$hash}) {
                                 push @delete, $keep{$name}{$hash};                                  push @delete, $keep{$name}{$hash};
                                 $keep{$name}{$hash} =                                  $keep{$name}{$hash} =
                                         $files{$name}{$time}{file};                                          $files{$name}{$epoch}{file};
                         } else {                          } else {
                                 push @delete, $files{$name}{$time}{file};                                  push @delete, $files{$name}{$epoch}{file};
                         }                          }
                 } else {                  } else {
                         $keep{$name}{$hash} =                          $keep{$name}{$hash} =
                                 $files{$name}{$time}{file};                                  $files{$name}{$epoch}{file};
   
                 }                  }
         }          }
Line 74 
Line 103 
   
 foreach (@delete) {  foreach (@delete) {
         print "Deleting '$_'\n";          print "Deleting '$_'\n";
         unlink "$TorrentDir/$_" or die "Couldn't unlink $_";          unlink $OBT->{DIR_TORRENT} . "/$_" or die "Couldn't unlink $_";
 }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.11

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