=================================================================== RCS file: /cvs/openbsd/OpenBSDTorrents/CurrentTorrents.pl,v retrieving revision 1.34 retrieving revision 1.38 diff -u -r1.34 -r1.38 --- openbsd/OpenBSDTorrents/CurrentTorrents.pl 2010/03/03 18:31:57 1.34 +++ openbsd/OpenBSDTorrents/CurrentTorrents.pl 2010/03/22 21:36:28 1.38 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -#$RedRiver: CurrentTorrents.pl,v 1.33 2010/03/03 18:15:31 andrew Exp $ +#$RedRiver: CurrentTorrents.pl,v 1.37 2010/03/16 22:40:18 andrew Exp $ use strict; use warnings; use diagnostics; @@ -58,12 +58,12 @@ $name = $base; } - #print "Adding $_\n"; + #print "Adding $DIR/$_\n"; - $files{$ext}{$name}{$epoch} = { + my $ct = { file => $_, dir => $DIR, - path => "$DIR/$_", + #path => "$DIR/$_", ext => $ext, #year => $year, @@ -78,9 +78,18 @@ if ( $name =~ m/\A $OBT->{BASENAME} /xms && !exists $Possible_Torrents{$name} ) { - #print "Would remove $_\n"; - push @delete, $files{$ext}{$name}{$epoch}; + print "Would remove impossible $_\n"; + 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; } @@ -100,7 +109,7 @@ EPOCH: foreach my $epoch ( sort { $b <=> $a } keys %{$cn} ) { my $ct = $cn->{$epoch}; - my $cf = $ct->{path}; + my $cf = $ct->{dir} . '/' . $ct->{file}; #print "\t$epoch - $cf\n"; @@ -136,7 +145,7 @@ if ( $seen{$name} && $seen{$name} ne $hash ) { print "Removing older [$name] [$hash]\n\t", - $ct->{path}, + $cf, "\n"; $ct->{reason} = 'older'; push @delete, $ct; @@ -151,7 +160,7 @@ } print "Removing duplicate [$name] [$hash]\n\t", - $keep{$hash}{path}, "\n"; + $keep{$hash}{file}, "\n"; $keep{$hash}{reason} = 'duplicate'; $ct->{reason} = 'duplicate'; @@ -207,12 +216,14 @@ or die "Couldn't rename '$file': $!"; $dir = $OBT->{DIR_TORRENT}; + $keep{$hash}{dir} = $dir; if ( exists $files{txt}{$name}{$epoch} ) { my $m_file = $files{txt}{$name}{$epoch}{file}; my $m_dir = $files{txt}{$name}{$epoch}{dir}; rename( "$m_dir/$m_file", $OBT->{DIR_TORRENT} . "/" . $m_file ) or die "Couldn't rename '$m_file': $!"; + $files{txt}{$name}{$epoch}{dir} = $OBT->{DIR_TORRENT}; } } @@ -226,16 +237,17 @@ { #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}; } } } foreach (@delete) { - if ( $_->{path} ) { - print "Deleting '$_->{path}'\n"; - unlink $_->{path} or die "Couldn't unlink $_->{path}"; + my $path = $_->{dir} . '/' . $_->{file}; + if ( -e $path ) { + print "Deleting '$path'\n"; + unlink $path or die "Couldn't delete $path"; delete $files{torrent}{ $_->{name} }{ $_->{epoch} }; } else { @@ -247,7 +259,10 @@ foreach my $name ( keys %{ $files{ $OBT->{META_EXT} } } ) { foreach my $epoch ( keys %{ $files{ $OBT->{META_EXT} }{$name} } ) { 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"; unlink $path or die "couldn't unlink '$path': $!"; } @@ -267,6 +282,9 @@ foreach my $file (@$files) { if ( $file =~ /$INSTALL_ISO_REGEX/ ) { Make_Possible("$dir/$file"); + } + elsif ( $file =~ /$SONG_REGEX/xms ) { + Make_Possible("$dir/$1"); } } }