=================================================================== RCS file: /cvs/openbsd/OpenBSDTorrents/ServerTorrents.pl,v retrieving revision 1.23 retrieving revision 1.26 diff -u -r1.23 -r1.26 --- openbsd/OpenBSDTorrents/ServerTorrents.pl 2007/10/01 21:17:23 1.23 +++ openbsd/OpenBSDTorrents/ServerTorrents.pl 2008/12/29 22:02:14 1.26 @@ -1,5 +1,5 @@ #!/usr/bin/perl -T -#$RedRiver: ServerTorrents.pl,v 1.22 2006/07/24 18:03:53 andrew Exp $ +#$RedRiver: ServerTorrents.pl,v 1.25 2008/09/23 16:35:45 andrew Exp $ use strict; use warnings; use diagnostics; @@ -35,7 +35,7 @@ my ($name, $hash, $disabled) = split /\t/; next if $name eq 'File'; - $name =~ s#^/torrents/##; + $name =~ s#.*/##; $server_torrents{$name}{$hash} = $disabled; } } @@ -99,10 +99,9 @@ foreach my $epoch ( sort { $b <=> $a } keys %{ $files{$name} } ) { #print "\t$epoch\n"; my $torrent = $files{$name}{$epoch}{file}; + my $hash = unpack("H*", $files{$name}{$epoch}{'details'}->info_hash ); + #printf "LOCAL: [%s] [%s]\n", $hash, $torrent; - my $hash = $files{$name}{$epoch}{'details'}->info_hash; - $hash = unpack("H*", $hash); - $torrents{$torrent}{$hash} = $files{$name}{$epoch}; unless (exists $server_torrents{$torrent}{$hash}) { @@ -113,9 +112,10 @@ foreach my $torrent (keys %server_torrents) { foreach my $hash (keys %{ $server_torrents{$torrent} }) { - unless ( - exists $torrents{$torrent}{$hash} || - $server_torrents{$torrent}{$hash} == 1 + #printf "SERVER: [%s] [%s]\n", $hash, $torrent; + if ((! exists $torrents{$torrent}{$hash}) && + defined $server_torrents{$torrent}{$hash} && + $server_torrents{$torrent}{$hash} != 1 ) { Delete_Torrent($torrent, $hash); } @@ -159,7 +159,7 @@ $comment =~ s/\n.*$//s; my $filename = - $comment =~ /Files from (.+)/ ? $1 + $comment =~ /($OBT->{BASENAME}.+)/ ? $1 : $file; $filename =~ s#/# #g; $filename =~ s/\.torrent\z//; @@ -193,7 +193,7 @@ my $hash = shift; die "No hash passed!" unless $hash; - print "Disabling $filename\n"; + print "Removing $filename [$hash]\n"; my $response = $ua->post($OBT->{'URL_DELETE'}, { username => $OBT->{UPLOAD_USER}, @@ -203,13 +203,19 @@ }, Content_Type => 'form-data'); if ($response->is_success) { - #print $response->content; - if ($response->content =~ /Torrent was removed successfully/) { - print STDERR "Disabled $filename\n"; - } else { - print STDERR "An error occoured removing $filename\n"; + my ($result) = $response->content =~ /class="error"\>([^<]+)\status_line; + elsif ($result) { + print STDERR "Error: $result (removing $filename [$hash])\n"; + } + else { + print STDERR "An unknown error occurred removing $filename [$hash]\n"; + } + } + else { + die $response->status_line . " removing $filename [$hash]\n"; } }