Ignore:
Timestamp:
01/23/11 10:55:48 (13 years ago)
Author:
nanardon
Message:
  • many fixes and optimisations
File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/lib/Sophie/Base/Header.pm

    r42 r332  
    1111 
    1212sub new { 
    13     my ($class, $pkgid) = @_; 
     13    my ($class, $pkgid, $db) = @_; 
    1414 
    15     bless({ key => $pkgid }, $class); 
     15    bless({ key => $pkgid, db => $db }, $class); 
    1616} 
    1717 
    1818sub key { $_[0]->{key} } 
     19sub db  { 
     20    $_[0]->{db}->storage->dbh 
     21} 
    1922 
    2023sub rpm_path { 
     
    5962    my $add_content = $self->db->prepare_cached( 
    6063        q{ 
    61         UPDATE allfiles set contents = ? where pkgid = ? and count = ? 
     64        UPDATE allfiles set contents = ?, has_content = ? where pkgid = ? and count = ? 
    6265        } 
    6366    ); 
     
    6972            sub { 
    7073                my ($file) = @_; 
    71                 my ($dirname, $basename) = $file->name =~ /^(?:\.(.*\/))?([^\/]+)$/; 
    72                 $dirname ||= ''; 
    73                 my $entry = $files->{$dirname}{$basename}; 
     74                my $fname = $file->name; 
     75                $fname =~ s/^\.\///; 
     76                my ($dirname, $basename) = $fname =~ /^(.*\/)?([^\/]+)$/; 
     77                $dirname = $rpm =~ /src.rpm$/ 
     78                    ? '' 
     79                    : $dirname ? "/$dirname" : '' ; 
     80                my $entry = $files->{$dirname}{$basename} or do { 
     81                    warn "unknown $dirname, $basename"; 
     82                    return 1; 
     83                }; 
    7484                for (1) { 
    75                     $entry->{size} > 1024 * 1024 and return 1; 
     85                    $entry->{flags} == 32 and last; 
     86                    my $maxsize = $dirname eq '' ? 2 * 1024 : 50; 
     87                    $entry->{size} > $maxsize * 1024 and return 1; 
     88                    $basename =~ /\.gz$/ and return; 
    7689                    # Spec files and patch 
    77                     $entry->{flags} == 32 and last; 
    7890                    $dirname eq '' and last; 
    7991                    # Doc files 
     
    8698                    return 1; 
    8799                } 
    88                 my $content = $file->get_content; 
    89                 my $enc = guess_encoding($content, qw/latin1/); 
     100                my $rawcontent = $file->get_content; 
     101                my $enc = guess_encoding($rawcontent, qw/latin1/); 
    90102                if ($enc && ref $enc) { 
    91                     $content = $enc->decode($content); 
     103                    my $content = $enc->decode($rawcontent); 
    92104 
    93105                    $self->db->pg_savepoint('FILECONTENT'); 
    94106                    $add_content->execute( 
    95                         $enc && ref $enc ? encode('utf8', $enc->decode($content)) : $content, 
     107                        $enc && ref $enc ? encode('utf8', $content) : $rawcontent, 
     108                        1, 
    96109                        $self->key, 
    97110                        $entry->{count}) or do { 
    98                         $self->db->pg_rollback_to('FILECONTENT'); 
    99                     }; 
    100                 } else { 
    101                 } 
     111                            $self->db->pg_rollback_to('FILECONTENT'); 
     112                        }; 
     113                    } 
    102114                1; 
    103115            } 
Note: See TracChangeset for help on using the changeset viewer.