Changeset 18 for server


Ignore:
Timestamp:
11/23/10 00:11:46 (14 years ago)
Author:
nanardon
Message:
  • improve database error management
  • add options to command line
Location:
server/trunk/web
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/bin/sophie_scan

    r10 r18  
    77use Linux::Inotify2; 
    88use POSIX ":sys_wait_h"; 
     9use Getopt::Long; 
    910 
    10 $SIG{ALRM} = sub {}; 
     11GetOptions( 
     12    'bdelay=i' =>  \my $updated_inotify, 
     13    'd|daemon'  => \my $daemon, 
     14) or die "Wrong options"; 
     15 
    1116$SIG{CHLD} = sub { wait }; 
    1217 
    1318my %modified_paths; 
     19my $inotify = undef; 
     20$updated_inotify ||= 300; 
    1421 
     22if ($daemon) { 
     23    if (fork()) { 
     24        exit(0); 
     25    } 
     26} 
     27 
     28alarm($updated_inotify); 
    1529while (1) { 
    16     alarm 30; 
     30    local $SIG{ALRM} = sub { 
     31        $inotify = undef; 
     32        warn "reparse paths"; 
     33        alarm($updated_inotify); 
     34    }; 
    1735    if (update_base(keys %modified_paths)) { 
    1836        %modified_paths = (); 
    1937    } 
    20     my $inotify = inotify_path(); 
     38    $inotify ||= inotify_path(); 
    2139    $inotify->poll; 
    2240} 
     
    3553                warn $e->w->name; 
    3654                $modified_paths{$e->w->name} = 1; 
     55                1; 
    3756            } 
    3857        ) 
     
    5372    my @pkey; 
    5473    { 
    55         my $sophie = Sophie::Base->connect; 
     74        my $sophie = Sophie::Base->connect or do { 
     75            die "cannot read config file\n"; 
     76        }; 
    5677        @pkey = $sophie->resultset('Paths')->search( 
    5778            path => [ @path ], 
     
    100121        } 
    101122        1 while(waitpid(-1, 0) <= 0); 
     123        exit(0); 
    102124    } 
    103125    return 1; 
  • server/trunk/web/lib/Sophie.pm

    r16 r18  
    2020    Session::State::Cookie 
    2121    Compress::Zlib 
    22     Server 
    23     Server::XMLRPC 
    2422    Authentication 
    2523/; 
  • server/trunk/web/lib/Sophie/Base.pm

    r5 r18  
    55use DBI; 
    66use base qw/DBIx::Class::Schema/; 
     7use FindBin qw($Bin); 
    78 
    89__PACKAGE__->load_namespaces(); 
     
    1718sub db { 
    1819   my ($self) = @_; 
    19    require Sophie; 
     20   require Config::General; 
     21   my $cg = Config::General->new("$Bin/../sophie.conf"); 
     22   my $config = { $cg->getall() }; 
    2023 
    2124   DBI->connect_cached( 
    22        'dbi:Pg:' . Sophie->config->{dbconnect}, 
    23        Sophie->config->{dbuser}, 
    24        Sophie->config->{dbpassword}, 
     25       'dbi:Pg:' . $config->{dbconnect}, 
     26       $config->{dbuser}, 
     27       $config->{dbpassword}, 
    2528       { 
    2629           AutoCommit => 0, 
  • server/trunk/web/lib/Sophie/Base/Header.pm

    r10 r18  
    104104 
    105105    $tmp = undef; 
     106    return 1; 
    106107} 
    107108 
  • server/trunk/web/lib/Sophie/Base/RpmsPath.pm

    r7 r18  
    113113        } 
    114114    ); 
    115     $remove->execute($$self, $rpm); 
    116     warn "deleting $rpm"; 
    117     $self->db->commit; 
     115    for (1 .. 3) { 
     116        if ($remove->execute($$self, $rpm)) {  
     117            warn "deleting $rpm"; 
     118            $self->db->commit; 
     119            return 1; 
     120        } 
     121        $self->db->rollback; 
     122    } 
    118123} 
    119124 
     
    121126    my ($self, $rpm) = @_; 
    122127 
    123     if (my $pkgid = $self->_add_header($rpm)) { 
    124         my $register = $self->db->prepare_cached( 
    125             q{ 
    126             INSERT INTO rpmfiles (d_path, filename, pkgid) 
    127             values (?,?,?) 
     128    for (1 .. 3) { 
     129        if (defined(my $pkgid = $self->_add_header($rpm))) { 
     130            $pkgid or return; 
     131            my $register = $self->db->prepare_cached( 
     132                q{ 
     133                INSERT INTO rpmfiles (d_path, filename, pkgid) 
     134                values (?,?,?) 
     135                } 
     136            ); 
     137            if ($register->execute($$self, $rpm, $pkgid)) { 
     138                warn "adding $rpm"; 
     139                $self->db->commit; 
     140                return; 
    128141            } 
    129         ); 
    130         $register->execute($$self, $rpm, $pkgid); 
    131  
    132     } else { 
    133     } 
    134     warn "adding $rpm"; 
    135     $self->db->commit; 
     142 
     143        } 
     144        $self->db->rollback; 
     145    } 
    136146} 
    137147 
     
    145155    $header or do { 
    146156        warn "Cannot read " . $self->path . '/' . $rpm; 
    147         return; 
     157        return ""; 
    148158    }; 
    149159 
     
    197207        } 
    198208    ); 
    199     $index_tag->execute($header->queryformat('%{PKGID}')); 
     209    $index_tag->execute($header->queryformat('%{PKGID}')) or return; 
    200210    $index_tag->finish; 
    201211    Sophie::Base::Header->new($header->queryformat('%{PKGID}')) 
    202         ->addfiles_content({ path => $self->path, filename => $rpm}); 
     212        ->addfiles_content({ path => $self->path, filename => $rpm}) or return; 
    203213 
    204214    $header->queryformat('%{PKGID}'); 
Note: See TracChangeset for help on using the changeset viewer.