[BACK]Return to OpenBSDTorrents.pm CVS log [TXT][DIR] Up to [local] / openbsd / OpenBSDTorrents / lib

Diff for /openbsd/OpenBSDTorrents/lib/OpenBSDTorrents.pm between version 1.8 and 1.15

version 1.8, 2005/05/20 19:36:34 version 1.15, 2010/05/26 20:41:15
Line 1 
Line 1 
 package OpenBSDTorrents;  package OpenBSDTorrents;
 #$Id$  #$RedRiver: OpenBSDTorrents.pm,v 1.14 2010/05/19 22:19:43 andrew Exp $
 use 5.008005;  use 5.008005;
 use strict;  use strict;
 use warnings;  use warnings;
Line 12 
Line 12 
   
 our @EXPORT = qw(  our @EXPORT = qw(
         $OBT          $OBT
           $INSTALL_ISO_REGEX
           $SONG_REGEX
         &Name_Torrent          &Name_Torrent
         &Get_Files_and_Dirs          &Get_Files_and_Dirs
         &justme          &justme
Line 19 
Line 21 
   
 my $config_file = '/etc/OpenBSDTorrents.conf';  my $config_file = '/etc/OpenBSDTorrents.conf';
 our $OBT = Config();  our $OBT = Config();
   our $INSTALL_ISO_REGEX = qr/ \b install\d+\.iso \b /xms;
   our $SONG_REGEX        = qr/^song.*\.([^\.]+)$/xms;
   
 sub Config  sub Config
 {  {
Line 35 
Line 39 
                 # bit safer, but I can't think of what would work here.                  # bit safer, but I can't think of what would work here.
                 if ($val =~ /^(.*)$/) {                  if ($val =~ /^(.*)$/) {
                         $config{$name} = $1;                          $config{$name} = $1;
                           $config{$name} =~ s/^['"]|["']$//gxms;
                 }                  }
         }          }
         close FILE;          close FILE;
Line 58 
Line 63 
 sub Get_Files_and_Dirs  sub Get_Files_and_Dirs
 {  {
         my $basedir = shift;          my $basedir = shift;
   
           if ( -f $basedir ) {
                   $basedir =~ s{^.*/}{}xms;
                   return [], [ $basedir ];
           }
   
         opendir DIR, $basedir or die "Couldn't opendir $basedir: $!";          opendir DIR, $basedir or die "Couldn't opendir $basedir: $!";
         my @contents = sort grep { ! /^\.\.$/ } grep { ! /^\.$/ } readdir DIR;          my @contents = sort grep { ! /^\.\.$/ } grep { ! /^\.$/ } readdir DIR;
         closedir DIR;          closedir DIR;
         my @dirs  = grep { -d "$basedir/$_" } @contents;  
   
         my %dirs; # lookup table          my @dirs;
         my @files;# answer          my @files;
           ITEM: foreach my $item (@contents) {
         # build lookup table                  if ( -d "$basedir/$item" ) {
         @dirs{@dirs} = ();                          if ( $OBT->{SKIP_DIRS}
                             && $item =~ /$OBT->{SKIP_DIRS}/) {
         foreach my $item (@contents) {                                  next ITEM;
                 push(@files, $item) unless exists $dirs{$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;          return \@dirs, \@files;
 }  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.15

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>