=================================================================== RCS file: /cvs/openbsd/OpenBSDTorrents/lib/OpenBSDTorrents.pm,v retrieving revision 1.6 retrieving revision 1.13 diff -u -r1.6 -r1.13 --- openbsd/OpenBSDTorrents/lib/OpenBSDTorrents.pm 2005/03/28 22:59:42 1.6 +++ openbsd/OpenBSDTorrents/lib/OpenBSDTorrents.pm 2010/03/22 21:13:53 1.13 @@ -1,5 +1,5 @@ package OpenBSDTorrents; -#$Id: OpenBSDTorrents.pm,v 1.6 2005/03/28 22:59:42 andrew Exp $ +#$RedRiver: OpenBSDTorrents.pm,v 1.12 2010/03/22 19:08:48 andrew Exp $ use 5.008005; use strict; use warnings; @@ -11,26 +11,40 @@ our $VERSION = '0.01'; our @EXPORT = qw( - $BaseDir - $HomeDir - $TorrentDir - $BaseName - $Tracker + $OBT + $INSTALL_ISO_REGEX + $SONG_REGEX &Name_Torrent &Get_Files_and_Dirs &justme ); - -our $BaseDir = '/home/ftp/pub'; -our $HomeDir = '/home/OpenBSDTorrents'; -our $TorrentDir = '/home/torrentsync/torrents'; -our $BaseName = 'OpenBSD'; -our $Tracker = 'http://OpenBSD.somedomain.net/announce.php'; -# These are regexes that tell what files to skip; -our $SkipDirs = qr/\/patches$/; -our $SkipFiles = qr/^\./; +my $config_file = '/etc/OpenBSDTorrents.conf'; +our $OBT = Config(); +our $INSTALL_ISO_REGEX = qr/install\d+\.iso/xms; +our $SONG_REGEX = qr/^song.*\.([^\.]+)$/xms; +sub Config +{ + my %config; + open FILE, $config_file or die "Couldn't open FILE $config_file: $!"; + while () { + chomp; + s/#.*$//; + s/\s+$//; + next unless $_; + my ($name, $val) = split /=/, $_, 2; + $name =~ s/^OBT_//; + # This should really look for contents that are a + # bit safer, but I can't think of what would work here. + if ($val =~ /^(.*)$/) { + $config{$name} = $1; + $config{$name} =~ s/^['"]|["']$//gxms; + } + } + close FILE; + return \%config; +} sub Name_Torrent { @@ -52,21 +66,26 @@ opendir DIR, $basedir or die "Couldn't opendir $basedir: $!"; my @contents = sort grep { ! /^\.\.$/ } grep { ! /^\.$/ } readdir DIR; closedir DIR; - my @dirs = grep { -d "$basedir/$_" } @contents; - my %dirs; # lookup table - my @files;# answer - - # build lookup table - @dirs{@dirs} = (); - - foreach my $item (@contents) { - push(@files, $item) unless exists $dirs{$item}; + my @dirs; + my @files; + ITEM: foreach my $item (@contents) { + if ( -d "$basedir/$item" ) { + if ( $OBT->{SKIP_DIRS} + && $item =~ /$OBT->{SKIP_DIRS}/) { + next ITEM; + } + push @dirs, $item; + } + else { + if ( $OBT->{SKIP_FILES} + && $item =~ /$OBT->{SKIP_FILES}/) { + next ITEM; + } + push @files, $item; + } } - @dirs = grep { ! /$SkipDirs/ } @dirs if $SkipDirs; - @files = grep { ! /$SkipFiles/ } @files if $SkipFiles; - return \@dirs, \@files; } @@ -94,7 +113,7 @@ die "Couldn't figure out myname"; } - my $SEMA = "$HomeDir/$myname.pid"; + my $SEMA = $OBT->{DIR_HOME} . "/run/$myname.pid"; if (open SEMA, "<", $SEMA) { my $pid = ; if (defined $pid) {