=================================================================== RCS file: /cvs/openbsd/OpenBSDTorrents/lib/OpenBSDTorrents.pm,v retrieving revision 1.9 retrieving revision 1.14 diff -u -r1.9 -r1.14 --- openbsd/OpenBSDTorrents/lib/OpenBSDTorrents.pm 2006/05/15 19:47:04 1.9 +++ openbsd/OpenBSDTorrents/lib/OpenBSDTorrents.pm 2010/05/19 23:19:43 1.14 @@ -1,5 +1,5 @@ package OpenBSDTorrents; -#$RedRiver: OpenBSDTorrents.pm,v 1.8 2005/05/20 18:36:34 andrew Exp $ +#$RedRiver: OpenBSDTorrents.pm,v 1.13 2010/03/22 20:13:53 andrew Exp $ use 5.008005; use strict; use warnings; @@ -12,6 +12,8 @@ our @EXPORT = qw( $OBT + $INSTALL_ISO_REGEX + $SONG_REGEX &Name_Torrent &Get_Files_and_Dirs &justme @@ -19,6 +21,8 @@ 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 { @@ -35,6 +39,7 @@ # bit safer, but I can't think of what would work here. if ($val =~ /^(.*)$/) { $config{$name} = $1; + $config{$name} =~ s/^['"]|["']$//gxms; } } close FILE; @@ -58,25 +63,34 @@ sub Get_Files_and_Dirs { my $basedir = shift; + + if ( -f $basedir ) { + $basedir =~ s{^.*/}{}xms; + return [], [ $basedir ]; + } + 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 { ! /$OBT->{SKIP_DIRS}/ } @dirs - if $OBT->{SKIPDIRS}; - @files = grep { ! /$OBT->{SKIP_FILES}/ } @files - if $OBT->{SKIP_FILES}; return \@dirs, \@files; }