=================================================================== RCS file: /cvs/openbsd/OpenBSDTorrents/MakeTorrents.pl,v retrieving revision 1.10 retrieving revision 1.21 diff -u -r1.10 -r1.21 --- openbsd/OpenBSDTorrents/MakeTorrents.pl 2005/04/06 23:56:50 1.10 +++ openbsd/OpenBSDTorrents/MakeTorrents.pl 2006/11/06 23:17:59 1.21 @@ -1,40 +1,47 @@ -#!/usr/bin/perl -T -#$Id: MakeTorrents.pl,v 1.10 2005/04/06 22:56:50 andrew Exp $ +#!/usr/bin/perl +# -T +#$RedRiver: MakeTorrents.pl,v 1.20 2006/07/24 18:03:53 andrew Exp $ use strict; use warnings; use diagnostics; -use BT::MetaInfo; - use lib 'lib'; +use BT::MetaInfo::Cached; use OpenBSDTorrents; %ENV = (); -use YAML; +chdir($OBT->{DIR_FTP}) || die "Couldn't change dir to " . $OBT->{DIR_FTP} . ": $!"; -my $StartDir = shift || $OBT->{BASENAME}; -$StartDir =~ s#/$##; +my $StartDir = ''; +if (@ARGV) { + foreach (@ARGV) { + s#/$##; + Process_Dir($_); + } +} else { + $StartDir = $OBT->{BASENAME}; + Process_Dir($StartDir); +} -chdir($OBT->{DIR_FTP}) || die "Couldn't change dir to " . $OBT->{DIR_FTP} . ": $!"; -Process_Dir($StartDir); sub Process_Dir { my $basedir = shift; + #return undef if $basedir =~ /packages/; + my ($dirs, $files) = Get_Files_and_Dirs($basedir); if (@$files) { my $torrent = Make_Torrent($basedir, $files); } - # don't recurse if we were called on a specific directory + # don't recurse if we were started with a specific directory return 1 if $StartDir ne $OBT->{BASENAME}; foreach my $subdir (@$dirs) { - next if $subdir eq '.'; - next if $subdir eq '..'; + next if $subdir =~ /^\./; Process_Dir("$basedir/$subdir") } } @@ -73,7 +80,7 @@ eval { btmake($torrent, $comment, $files); }; if ($@) { - print "Error creating $torrent\n"; + print "Error creating $torrent\n$@\n"; } # system($BTMake, @@ -101,9 +108,14 @@ my $announce = $OBT->{URL_TRACKER}; my $piece_len = 2 << ($OBT->{PIECE_LENGTH} - 1); - $torrent = $OBT->{DIR_TORRENT} . "/$torrent"; + my $torrent_with_path = $OBT->{DIR_NEW_TORRENT} . "/$torrent"; - my $t = BT::MetaInfo->new(); + my $t = BT::MetaInfo::Cached->new( + { + cache_root => '/tmp/OBTFileCache' + } + ); + $t->name($name); $t->announce($announce); unless ($announce =~ m!^http://[^/]+/!i) { @@ -125,8 +137,10 @@ return 0; } - $t->save("$torrent"); - print "Created: $torrent\n"; - #system("btinfo $torrent") if ($::opt_I); + my $hash = $t->info_hash; + $hash = unpack("H*", $hash); + + $t->save($torrent_with_path); + print "Created: $torrent_with_path\n"; }