[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.2 and 1.10

version 1.2, 2005/03/22 23:44:43 version 1.10, 2007/11/02 03:36:01
Line 1 
Line 1 
 package OpenBSDTorrents;  package OpenBSDTorrents;
 #$Id$  #$RedRiver: OpenBSDTorrents.pm,v 1.9 2006/05/15 18:47:04 andrew Exp $
 use 5.008005;  use 5.008005;
 use strict;  use strict;
 use warnings;  use warnings;
Line 11 
Line 11 
 our $VERSION = '0.01';  our $VERSION = '0.01';
   
 our @EXPORT = qw(  our @EXPORT = qw(
         $BaseDir          $OBT
         $TorrentDir          $INSTALL_ISO_REGEX
         $BaseName  
         $Tracker  
         &Name_Torrent          &Name_Torrent
         &Get_Files_and_Dirs          &Get_Files_and_Dirs
           &justme
 );  );
   
 our $BaseDir  = '/home/ftp/pub';  
 our $TorrentDir   = '/home/andrew/torrents';  
 our $BaseName = 'OpenBSD';  
 our $Tracker  = 'http://OpenBSD.somedomain.net/announce.php';  
   
 # These are regexes that tell what files to skip;  my $config_file = '/etc/OpenBSDTorrents.conf';
 our $SkipDirs  = qr/\/patches$/;  our $OBT = Config();
 our $SkipFiles = qr/^\./;  our $INSTALL_ISO_REGEX = qr/install\d+\.iso/;
   
   sub Config
   {
           my %config;
           open FILE, $config_file or die "Couldn't open FILE $config_file: $!";
           while (<FILE>) {
                   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;
                   }
           }
           close FILE;
           return \%config;
   }
   
 sub Name_Torrent  sub Name_Torrent
 {  {
Line 47 
Line 61 
 {  {
         my $basedir = shift;          my $basedir = shift;
         opendir DIR, $basedir or die "Couldn't opendir $basedir: $!";          opendir DIR, $basedir or die "Couldn't opendir $basedir: $!";
         my @contents = grep { ! /^\.\.$/ } grep { ! /^\.$/ } readdir DIR;          my @contents = sort grep { ! /^\.\.$/ } grep { ! /^\.$/ } readdir DIR;
         closedir DIR;          closedir DIR;
         my @dirs  = grep { -d "$basedir/$_" } @contents;          my @dirs  = grep { -d "$basedir/$_" } @contents;
   
Line 61 
Line 75 
                 push(@files, $item) unless exists $dirs{$item};                  push(@files, $item) unless exists $dirs{$item};
         }          }
   
         @dirs  = grep { ! /$SkipDirs/  } @dirs  if $SkipDirs;          @dirs  = grep { ! /$OBT->{SKIP_DIRS}/  } @dirs
         @files = grep { ! /$SkipFiles/ } @files if $SkipFiles;                  if $OBT->{SKIPDIRS};
           @files = grep { ! /$OBT->{SKIP_FILES}/ } @files
                   if $OBT->{SKIP_FILES};
   
         return \@dirs, \@files;          return \@dirs, \@files;
 }  }
Line 79 
Line 95 
         }          }
         return join '-', ($year, $mon, $mday, $hour . $min);          return join '-', ($year, $mon, $mday, $hour . $min);
 }  }
   
   # "There can be only one."  --the Highlander
   sub justme {
   
           my $myname;
   
           if ($0 =~ m#([^/]+$)#) {
                   $myname = $1;
           } else {
                   die "Couldn't figure out myname";
           }
   
           my $SEMA = $OBT->{DIR_HOME} . "/run/$myname.pid";
           if (open SEMA, "<", $SEMA) {
                   my $pid = <SEMA>;
                   if (defined $pid) {
                           chomp $pid;
                           if ($pid =~ /^(\d+)$/) {
                                   $pid = $1;
                           } else {
                                   die "invalid pid read '$pid'";
                           }
                           if (kill(0, $pid)) {
                                 print "$0 already running (pid $pid), bailing out\n";
                                 exit 253;
                           }
                   }
                   close SEMA;
           }
           open (SEMA, ">", $SEMA)      or die "can't write $SEMA: $!";
           print SEMA "$$\n";
           close(SEMA)                    or die "can't close $SEMA: $!";
   }
   
   
 1;  1;
 __END__  __END__

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.10

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