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

Diff for /openbsd/OpenBSDTorrents/lib/BT/MetaInfo/Cached.pm between version 1.2 and 1.3

version 1.2, 2005/05/02 20:43:44 version 1.3, 2005/05/02 22:46:48
Line 6 
Line 6 
 require 5.6.0;  require 5.6.0;
 use vars qw( $VERSION @ISA );  use vars qw( $VERSION @ISA );
   
   use Digest::SHA1 qw(sha1);
   use Fcntl ':flock'; # import LOCK_* constants
   
 use BT::MetaInfo;  use BT::MetaInfo;
   use base 'BT::MetaInfo';
   
   use OpenBSDTorrents;
   
 use Data::Dumper;  use Data::Dumper;
   
 $VERSION = do { my @r = (q$Id$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };  $VERSION = do { my @r = (q$Id$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
Line 15 
Line 21 
 sub new  sub new
 {  {
         my $classname   = shift;          my $classname   = shift;
         print Dumper $classname;          return $classname->SUPER::new(@_);
         exit;  
   
 #       my $self        = $classname->SUPER::new(@_);  
 }  }
   
   
 sub info_hash { return(sha1(bencode($_[0]->info))); }  sub info_hash_cached
   {
           my $self = shift;
           my $torrent = shift;
   
           return $self->SUPER::info_hash unless $torrent;
   
           my $meta_file = $torrent;
           $meta_file =~ s/\.torrent$/.$OBT->{META_EXT}/;
   
           my $hash = undef;
   
           if (-e $meta_file) {
                   #print "Reading meta file: $meta_file\n";
                   open my $meta, $meta_file or die "Couldn't open $meta_file: $!";
                   flock($meta, LOCK_SH);
                   binmode $meta;
   
                   $hash = do { local $/; <$meta> };
   
                   flock($meta, LOCK_UN);
                   close $meta;
           } else {
                   $hash = $self->SUPER::info_hash;
                   #print "Writing meta file: $meta_file\n";
                   open my $meta, '>', $meta_file
                           or die "Couldn't open $meta_file: $!";
                   flock($meta, LOCK_EX);
                   binmode $meta;
   
                   print $meta $hash;
   
                   flock($meta, LOCK_UN);
                   close $meta;
   
           }
           #my $text_hash = unpack("H*", $hash);
           #print "INFO_HASH: $text_hash\n";
   
           return $hash;
   }
   
 1  1

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

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