| 1 | package CPAN::Testers::Data::Uploads; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 13 | $VERSION = '0.20'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | $|++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # Library Modules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use base qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use CPAN::DistnameInfo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | ▶ | use CPAN::Testers::Common::DBUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 13 | ▶ | use CPAN::Testers::Common::Article; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | ▶ | use Config::IniFiles; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 13 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 13 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | ▶ | use File::Find::Rule; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 13 | ▶ | use File::Path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 13 | ▶ | use File::Slurp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 13 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 13 | ▶ | use IO::AtomicFile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 13 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 13 | ▶ | use Net::NNTP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # Variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 13 | my (%backups); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 13 | ▶ | use constant LASTMAIL => '_lastmail'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 13 | ▶ | use constant LOGFILE => '_uploads.log'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 13 | ▶ | use constant JOURNAL => '_journal.sql'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 13 | my %phrasebook = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 'FindAuthor' => 'SELECT * FROM ixlatest WHERE author=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'FindDistVersion' => 'SELECT type FROM uploads WHERE author=? AND dist=? AND version=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 'InsertDistVersion' => 'INSERT INTO uploads (type,author,dist,version,filename,released) VALUES (?,?,?,?,?,?)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 'UpdateDistVersion' => 'UPDATE uploads SET type=? WHERE author=? AND dist=? AND version=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 'FindDistTypes' => 'SELECT * FROM uploads WHERE type=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 'DeleteAll' => 'DELETE FROM uploads', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 'SelectAll' => 'SELECT * FROM uploads', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'DeleteAllIndex' => 'DELETE FROM ixlatest', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 'DeleteIndex' => 'DELETE FROM ixlatest WHERE dist=? AND author=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 'FindIndex' => 'SELECT * FROM ixlatest WHERE dist=? AND author=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 'InsertIndex' => 'INSERT INTO ixlatest (oncpan,author,version,released,dist) VALUES (?,?,?,?,?)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 'AmendIndex' => 'UPDATE ixlatest SET oncpan=? WHERE author=? AND version=? AND dist=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 'UpdateIndex' => 'UPDATE ixlatest SET oncpan=?,version=?,released=? WHERE dist=? AND author=?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 'BuildAuthorIndex' => 'SELECT x.author,x.version,x.released,x.dist,x.type FROM (SELECT dist, MAX(released) AS mv FROM uploads WHERE author=? GROUP BY dist) AS y INNER JOIN uploads AS x ON x.dist=y.dist AND x.released=y.mv ORDER BY released', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 'GetAllAuthors' => 'SELECT distinct(author) FROM uploads', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 'InsertRequest' => 'INSERT INTO page_requests (type,name,weight) VALUES (?,?,5)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 'ParseFailed' => 'REPLACE INTO uploads_failed (source,type,dist,version,file,pause,created) VALUES (?,?,?,?,?,?,?)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # SQLite backup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 'CreateTable' => 'CREATE TABLE uploads (type text, author text, dist text, version text, filename text, released int)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 13 | my $extn = qr/\.(tar\.(gz|bz2)|tgz|zip)$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 13 | my %oncpan = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 'backpan' => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 'cpan' => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 'upload' => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # The Application Programming Interface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 14 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 14 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 14 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 14 | $self->_init_options(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 13 | __PACKAGE__->mk_accessors( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | qw( uploads backpan cpan logfile logclean lastfile journal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | mgenerate mupdate mbackup mreindex )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | sub process { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | ▶ | $self->generate() if($self->mgenerate); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 5 | ▶ | $self->reindex() if($self->mreindex); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 5 | ▶ | $self->update() if($self->mupdate); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 5 | ▶ | $self->backup() if($self->mbackup); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | sub generate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my $db = $self->uploads; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | $self->_log("Restarting uploads database"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | $db->do_query($phrasebook{'DeleteAll'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | $self->_log("Creating BACKPAN entries"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | my @files = File::Find::Rule->file()->name($extn)->in($self->backpan); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | $self->_parse_archive('backpan',$_) for(@files); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | $self->_log("Creating CPAN entries"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | @files = File::Find::Rule->file()->name($extn)->in($self->cpan); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | $self->_parse_archive('cpan',$_) for(@files); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | sub reindex { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reindex: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | my $db = $self->uploads; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | $self->_log("Reindexing by author"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | my $next = $db->iterator('hash',$phrasebook{'GetAllAuthors'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | ▶ | while(my $author = $next->()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 45 | $self->_log(".. author = $author->{author}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 45 | my @rows = $db->get_query('hash',$phrasebook{'BuildAuthorIndex'},$author->{author}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 45 | for my $row (@rows) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 51 | $self->_log(".... dist = $row->{dist}, latest = $row->{version}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 51 | $db->do_query($phrasebook{'DeleteIndex'},$row->{dist},$row->{author}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 51 | $db->do_query($phrasebook{'InsertIndex'},$oncpan{$row->{type}},$row->{author},$row->{version},$row->{released},$row->{dist}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 3 | $self->_log("Reindexing authors done"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | sub update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=15 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | my $db = $self->uploads; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | $self->_open_journal(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # get list of db known CPAN distributions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | my @rows = $db->get_query('hash',$phrasebook{'FindDistTypes'},'cpan'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | my %cpan = map {$_->{filename} => $_} @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # get currently mirrored CPAN entries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | $self->_log("Updating CPAN entries"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | my @files = File::Find::Rule->file()->name($extn)->in($self->cpan); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | for(@files) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 63 | ▶ | if(my $file = $self->_parse_archive('cpan',$_,1)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 63 | delete $cpan{$file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | #$self->_log(".. cannot parse: $_"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # demote any distributions no longer on CPAN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | $self->_log("Updating BACKPAN entries"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | for my $file (keys %cpan) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | #$self->_log("backpan => $cpan{$file}->{dist} => $cpan{$file}->{version} => $cpan{$file}->{author} => $cpan{$file}->{released}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $self->_write_journal('UpdateDistVersion','backpan',$cpan{$file}->{author},$cpan{$file}->{dist},$cpan{$file}->{version}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $db->do_query($phrasebook{'AmendIndex'},2,$cpan{$file}->{author},$cpan{$file}->{version},$cpan{$file}->{dist}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # read NNTP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | $self->_log("Updating NNTP entries"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | my ($nntp,$num,$first,$last) = $self->_nntp_connect(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | my $lastid = $self->_lastid(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | ▶ | return if($last <= $lastid); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | $self->_log(".. from $lastid to $last"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | ▶ | for(my $id = $lastid+1; $id <= $last; $id++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | #$self->_log("NNTP ID = $id"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 72870 | ▶ | my $article = join "", @{$nntp->article($id) || []}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 72870 | ▶ | next unless($article); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | my $object = CPAN::Testers::Common::Article->new($article); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 4 | ▶ | next unless($object); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 4 | $self->_log("... [$id] subject=".($object->subject())); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 4 | my ($name,$version,$cpanid,$date,$filename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 4 | ▶ | if($object->parse_upload()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 4 | $name = $object->distribution; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 4 | $version = $object->version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 4 | $cpanid = $object->author; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 4 | $date = $object->epoch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 4 | $filename = $object->filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | #$self->_log("... name=$name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | #$self->_log("... version=$version"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | #$self->_log("... cpanid=$cpanid"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | #$self->_log("... date=$date"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 4 | ▶ | next unless($name && $version && $cpanid && $date); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$name and $version and $cpanid and $date
$name and $version and $cpanid
$name and $version
MC/DC0%0/4
$name and $version and $cpanid and $date
$name
$version
$cpanid
$date
Truth table20%1/5
A and B and C and D
A= $nameB= $versionC= $cpanidD= $date
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | #$self->_log("upload => $name => $version => $cpanid => $date"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | $self->_update_index($cpanid,$version,$date,$name,1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | my @rows = $db->get_query('array',$phrasebook{'FindDistVersion'},$cpanid,$name,$version); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 4 | ▶ | next if(@rows); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | $self->_write_journal('InsertDistVersion','upload',$cpanid,$name,$version,$filename,$date); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | $self->_lastid($last); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | $self->_close_journal(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | sub backup { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
backup: called CC=18 SCAR=53.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | my $db = $self->uploads; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | ▶ | if(my @journals = $self->_find_journals()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | for my $driver (keys %backups) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | ▶ | if($driver =~ /(CSV|SQLite)/i && !$backups{$driver}{'exists'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$driver =~ /(CSV|SQLite)/i and not $backups{$driver}{"exists"}
MC/DC0%0/2
$driver =~ /(CSV|SQLite)/i and not $backups{$driver}{"exists"}
$driver =~ /(CSV|SQLite)/i
not $backups{$driver}{"exists"}
Truth table33%1/3
A and not(B)
A= $driver =~ /(CSV|SQLite)/iB= not $backups{$driver}{"exists"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 2 | $backups{$driver}{db}->do_query($phrasebook{'CreateTable'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | $backups{$driver}{'exists'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | for my $journal (@journals) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | next if($journal =~ /TMP$/); # don't process active journals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $self->_log("Processing journal $journal"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my $lines = $self->_read_journal($journal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | for my $line (@$lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my ($phrase,@args) = @$line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | for my $driver (keys %backups) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $backups{$driver}{db}->do_query($phrasebook{$phrase},@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $self->_done_journal($journal); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $self->_log("Processed journals"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | for my $driver (keys %backups) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if($backups{$driver}{'exists'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $backups{$driver}{db}->do_query($phrasebook{'DeleteAll'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } elsif($driver =~ /(CSV|SQLite)/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $backups{$driver}{db}->do_query($phrasebook{'CreateTable'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $backups{$driver}{'exists'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $self->_log("Backup via DBD drivers"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my $rows = $db->iterator('array',$phrasebook{'SelectAll'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | while(my $row = $rows->()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | for my $driver (keys %backups) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $backups{$driver}{db}->do_query($phrasebook{'InsertDistVersion'},@$row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # handle the CSV exception | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if($backups{CSV}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $self->_log("Backup to CSV file"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $backups{CSV}{db} = undef; # close db handle | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | my $fh1 = IO::File->new('uploads','r') or die "Cannot read temporary database file 'uploads'\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | my $fh2 = IO::File->new($backups{CSV}{dbfile},'w+') or die "Cannot write to CSV database file $backups{CSV}{dbfile}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | while(<$fh1>) { print $fh2 $_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $fh1->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $fh2->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | unlink('uploads'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | sub help { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 5 | ▶ | my ($self,$full,$mess) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 5 | ▶ | print "\n$mess\n\n" if($mess); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 5 | ▶ | if($full) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 4 | print <<HERE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | Usage: $0 --config=<file> [-g] [-r] [-u] [-b] [-h] [-v] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | [--logfile=<file>] [--logclean] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | [--lastmail=<file>] [--journal=<file>] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | --config=<file> database configuration file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | -g generate new database | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | -r reindex database (*) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | -u update existing database | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | -b backup database to portable files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | -h this help screen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | -v program version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | --logfile=<file> trace log file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | --logclean overwrite exisiting log file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | --lastmail=<file> last id file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | --journal=<file> SQL journal file path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | Notes: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | * A generate request automatically includes a reindex. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | HERE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 5 | print "$0 v$VERSION\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 5 | exit(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # Private Methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | sub _parse_archive { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 189 | ▶ | my ($self,$type,$file,$update) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_archive: called CC=10 SCAR=26.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 189 | my $db = $self->uploads; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 189 | my $dist = CPAN::DistnameInfo->new($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 189 | my $name = $dist->dist; # "CPAN-DistnameInfo" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 189 | my $version = $dist->version; # "0.02" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 189 | my $cpanid = $dist->cpanid; # "GBARR" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 189 | my $filename = $dist->filename; # "CPAN-DistnameInfo-0.02.tar.gz" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 189 | my $date = (stat($file))[9]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 189 | ▶ | unless($name && defined $version && $cpanid && $date) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$name and defined $version and $cpanid and $date
$name and defined $version and $cpanid
$name and defined $version
MC/DC0%0/4
$name and defined $version and $cpanid and $date
$name
defined $version
$cpanid
$date
Truth table20%1/5
A and B and C and D
A= $nameB= defined $versionC= $cpanidD= $date
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | #$self->_log("PARSE: FAIL file=$file, $type => $name => $version => $cpanid => $date => $filename"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $file =~ s!/opt/projects/CPAN/!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $db->do_query($phrasebook{'ParseFailed'},$file,$type,$name,$version,$filename,$cpanid,$date); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | #$self->_log("$type => $name => $version => $cpanid => $date"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 189 | my @rows = $db->get_query('array',$phrasebook{'FindDistVersion'},$cpanid,$name,$version); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 189 | ▶ | if(@rows) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 126 | ▶ | if($type ne $rows[0]->[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 63 | $db->do_query($phrasebook{'UpdateDistVersion'},$type,$cpanid,$name,$version); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 63 | ▶ | $self->_update_index($cpanid,$version,$date,$name,$oncpan{$type}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$update and $type ne "backpan"
MC/DC0%0/2
$update and $type ne "backpan"
$update
$type ne "backpan"
Truth table33%1/3
A and B
A= $updateB= $type ne "backpan"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | if($update && $type ne 'backpan'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 63 | $db->do_query($phrasebook{'InsertDistVersion'},$type,$cpanid,$name,$version,$filename,$date); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 63 | ▶ | $self->_update_index($cpanid,$version,$date,$name,$oncpan{$type}) if($update); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 189 | return $filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | sub _update_index { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 4 | ▶ | my ($self,$author,$version,$date,$name,$oncpan) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_index: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 4 | my $db = $self->uploads; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 4 | my @index = $db->get_query('hash',$phrasebook{'FindIndex'},$name,$author); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 4 | ▶ | if(@index) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 3 | ▶ | if($date > $index[0]->{released}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | $db->do_query($phrasebook{'UpdateIndex'},$oncpan,$version,$date,$name,$author); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | $self->_log("... index update [$author,$version,$date,$name,$oncpan]"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | $db->do_query($phrasebook{'InsertIndex'},$oncpan,$author,$version,$date,$name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | $self->_log("... index insert [$author,$version,$date,$name,$oncpan]"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # add to page_requests table to update letter index pages and individual pages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 4 | $db->do_query($phrasebook{'InsertRequest'},'ixauth',substr($author,0,1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 4 | $db->do_query($phrasebook{'InsertRequest'},'ixdist',substr($name,0,1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 4 | $db->do_query($phrasebook{'InsertRequest'},'author',$author); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 4 | $db->do_query($phrasebook{'InsertRequest'},'distro',$name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | sub _nntp_connect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # connect to NNTP server | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | ▶ | my $nntp = Net::NNTP->new("nntp.perl.org") or die "Cannot connect to nntp.perl.org"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_nntp_connect: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | my ($num,$first,$last) = $nntp->group("perl.cpan.uploads"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | return ($nntp,$num,$first,$last); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | sub _lastid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 6 | ▶ | my ($self,$id) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lastid: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 6 | my $f = $self->lastfile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 6 | ▶ | unless( -f $f) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 2 | mkpath(dirname($f)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 2 | overwrite_file( $f, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | ▶ | $id ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$id ||= 0
MC/DC0%0/1
$id ||= 0
$id
Truth table50%1/2
A
A= $id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 6 | ▶ | if($id) { overwrite_file( $f, $id ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 4 | else { $id = read_file($f); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 6 | return $id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # generate atomic journal file name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | sub _open_journal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_open_journal: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 1 | my @now = localtime(time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | my $file = sprintf "%s.%04d%02d%02d%02d%02d%02d", $self->journal, $now[5]+1900,$now[4]+1,$now[3],$now[2],$now[1],$now[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 1 | ▶ | $self->{current} = IO::AtomicFile->new($file,'w+') or die "Cannot write to journal file [$file]: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | sub _write_journal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 3 | ▶ | my ($self,$phrase,@args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_journal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 3 | my $fh = $self->{current}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 3 | print $fh "$phrase," . join(',',@args) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 3 | my $db = $self->uploads; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 3 | $db->do_query($phrasebook{$phrase},@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | sub _close_journal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_close_journal: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | $self->{current}->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | sub _find_journals { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_journals: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | my @files = glob($self->journal . '.*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | return @files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | sub _read_journal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | my ($self,$journal) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_journal: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | my $fh = IO::File->new($journal,'r') or die "Cannot read journal file [$journal]: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | while(<$fh>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my @fields = split(/,/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | push @lines, \@fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $fh->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | sub _done_journal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | my ($self,$journal) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_done_journal: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my $cmd = "mv $journal logs"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | system($cmd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | sub _init_options { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_options: called CC=46 SCAR=41.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 14 | my %hash = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 14 | my %options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 14 | GetOptions( \%options, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 'config=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 'generate|g', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 'update|u', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 'reindex|r', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 'backup|b', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 'journal|j=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 'logfile|l=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 'logclean=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 'lastfile=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 'help|h', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 'version|v' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # default to API settings if no command line option | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 14 | for(qw(config generate update reindex fast backup help version)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 112 | ▶ | $options{$_} ||= $hash{$_} if(defined $hash{$_}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$options{$_} ||= $hash{$_}
MC/DC0%0/2
$options{$_} ||= $hash{$_}
$options{$_}
$hash{$_}
Truth table33%1/3
A ||= B
A= $options{$_}B= $hash{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 14 | ▶ | $self->help(1) if($options{help}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 13 | ▶ | $self->help(0) if($options{version}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | $self->help(1,"Must specify at least one option from 'generate' (-g), 'reindex' (-r),\n'update' (-u) and/or 'backup' (-b)") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 12 | ▶ | unless($options{generate} || $options{update} || $options{backup} || $options{reindex}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$options{"generate"} or $options{"update"} or $options{"backup"} or $options{"reindex"}
$options{"generate"} or $options{"update"} or $options{"backup"}
$options{"generate"} or $options{"update"}
MC/DC100%4/4
$options{"generate"} or $options{"update"} or $options{"backup"} or $options{"reindex"}
$options{"generate"}
$options{"update"}
$options{"backup"}
$options{"reindex"}
Truth table100%5/5
A or B or C or D
A= $options{"generate"}B= $options{"update"}C= $options{"backup"}D= $options{"reindex"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 11 | ▶ | $self->help(1,"Must specific the configuration file") unless( $options{config}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 10 | ▶ | $self->help(1,"Configuration file [$options{config}] not found") unless(-f $options{config}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # load configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 9 | my $cfg = Config::IniFiles->new( -file => $options{config} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # configure sources | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 9 | ▶ | if($options{generate}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 1 | my $dir = $cfg->val('MASTER','BACKPAN'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 1 | ▶ | $self->help(1,"No source location for 'BACKPAN' in config file") if(! $dir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 1 | ▶ | $self->help(1,"Cannot find source location for 'BACKPAN': [$dir]") if(!-d $dir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 1 | $self->backpan($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 1 | $self->mgenerate(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 1 | $self->mreindex(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 9 | ▶ | if($options{generate} || $options{update}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$options{"generate"} or $options{"update"}
MC/DC100%2/2
$options{"generate"} or $options{"update"}
$options{"generate"}
$options{"update"}
Truth table100%3/3
A or B
A= $options{"generate"}B= $options{"update"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 7 | my $dir = $cfg->val('MASTER','CPAN'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 7 | ▶ | $self->help(1,"No source location for 'CPAN' in config file") if(! $dir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 7 | ▶ | $self->help(1,"Cannot find source location for 'CPAN': [$dir]") if(!-d $dir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 7 | $self->cpan($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 9 | ▶ | if($options{reindex}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 1 | $self->mreindex(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 9 | ▶ | $self->mupdate(1) if($options{update}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 9 | ▶ | $self->logfile( $hash{logfile} || $options{logfile} || $cfg->val('MASTER','logfile' ) || LOGFILE ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition37%3/8
$hash{'logfile'} || $options{'logfile'} || $cfg->val('MASTER', 'logfile') || '_uploads.log'
$hash{"logfile"} or $options{"logfile"} or $cfg->val("MASTER", "logfile")
$hash{"logfile"} or $options{"logfile"}
MC/DC0%0/3
$hash{'logfile'} || $options{'logfile'} || $cfg->val('MASTER', 'logfile') || '_uploads.log'
$hash{"logfile"}
$options{"logfile"}
$cfg->val("MASTER", "logfile")
Truth table25%1/4
A or B or C
A= $hash{"logfile"}B= $options{"logfile"}C= $cfg->val("MASTER", "logfile")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 9 | ▶ | $self->logclean( $hash{logclean} || $options{logclean} || $cfg->val('MASTER','logclean' ) || 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition62%5/8
$hash{'logclean'} || $options{'logclean'} || $cfg->val('MASTER', 'logclean') || 0
$hash{"logclean"} or $options{"logclean"} or $cfg->val("MASTER", "logclean")
$hash{"logclean"} or $options{"logclean"}
MC/DC33%1/3
$hash{'logclean'} || $options{'logclean'} || $cfg->val('MASTER', 'logclean') || 0
$hash{"logclean"}
$options{"logclean"}
$cfg->val("MASTER", "logclean")
Truth table50%2/4
A or B or C
A= $hash{"logclean"}B= $options{"logclean"}C= $cfg->val("MASTER", "logclean")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 9 | ▶ | $self->lastfile( $hash{lastfile} || $options{lastfile} || $cfg->val('MASTER','lastfile' ) || LASTMAIL ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition37%3/8
$hash{'lastfile'} || $options{'lastfile'} || $cfg->val('MASTER', 'lastfile') || '_lastmail'
$hash{"lastfile"} or $options{"lastfile"} or $cfg->val("MASTER", "lastfile")
$hash{"lastfile"} or $options{"lastfile"}
MC/DC0%0/3
$hash{'lastfile'} || $options{'lastfile'} || $cfg->val('MASTER', 'lastfile') || '_lastmail'
$hash{"lastfile"}
$options{"lastfile"}
$cfg->val("MASTER", "lastfile")
Truth table25%1/4
A or B or C
A= $hash{"lastfile"}B= $options{"lastfile"}C= $cfg->val("MASTER", "lastfile")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 9 | ▶ | $self->journal( $hash{journal} || $options{journal} || $cfg->val('MASTER','journal' ) || JOURNAL ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition62%5/8
$hash{'journal'} || $options{'journal'} || $cfg->val('MASTER', 'journal') || '_journal.sql'
$hash{"journal"} or $options{"journal"} or $cfg->val("MASTER", "journal")
$hash{"journal"} or $options{"journal"}
MC/DC33%1/3
$hash{'journal'} || $options{'journal'} || $cfg->val('MASTER', 'journal') || '_journal.sql'
$hash{"journal"}
$options{"journal"}
$cfg->val("MASTER", "journal")
Truth table50%2/4
A or B or C
A= $hash{"journal"}B= $options{"journal"}C= $cfg->val("MASTER", "journal")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # configure upload DB | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 9 | ▶ | $self->help(1,"No configuration for UPLOADS database") unless($cfg->SectionExists('UPLOADS')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 9 | ▶ | my %opts = map {$_ => ($cfg->val('UPLOADS',$_) || undef)} qw(driver database dbfile dbhost dbport dbuser dbpass); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 9 | my $db = CPAN::Testers::Common::DBUtils->new(%opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 9 | ▶ | $self->help(1,"Cannot configure UPLOADS database") unless($db); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 9 | $self->uploads($db); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # configure backup DBs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 9 | ▶ | if($options{backup}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 1 | ▶ | $self->help(1,"No configuration for BACKUPS with backup option") unless($cfg->SectionExists('BACKUPS')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 1 | my %available_drivers = map { $_ => 1 } DBI->available_drivers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 1 | my @drivers = $cfg->val('BACKUPS','drivers'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 1 | for my $driver (@drivers) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 2 | ▶ | unless($available_drivers{$driver}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | warn "No DBI support for '$driver', ignoring\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 2 | ▶ | $self->help(1,"No configuration for backup option '$driver'") unless($cfg->SectionExists($driver)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 2 | ▶ | my %opt = map {$_ => ($cfg->val($driver,$_) || undef)} qw(driver database dbfile dbhost dbport dbuser dbpass); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 2 | ▶ | $backups{$driver}{'exists'} = $driver =~ /SQLite/i ? -f $opt{database} : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # CSV is a bit of an oddity! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 2 | ▶ | if($driver =~ /CSV/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 1 | $backups{$driver}{'exists'} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | $backups{$driver}{'dbfile'} = $opt{dbfile}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | $opt{dbfile} = 'uploads'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 1 | unlink($opt{dbfile}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 2 | $backups{$driver}{db} = CPAN::Testers::Common::DBUtils->new(%opt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 2 | ▶ | $self->help(1,"Cannot configure BACKUPS database for '$driver'") unless($backups{$driver}{db}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 1 | ▶ | $self->mbackup(1) if(keys %backups); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | sub _log { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 120 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 120 | ▶ | my $log = $self->logfile or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 120 | ▶ | mkpath(dirname($log)) unless(-f $log); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 120 | ▶ | my $mode = $self->logclean ? 'w+' : 'a+'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 120 | $self->logclean(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 120 | my @dt = localtime(time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 120 | my $dt = sprintf "%04d/%02d/%02d %02d:%02d:%02d", $dt[5]+1900,$dt[4]+1,$dt[3],$dt[2],$dt[1],$dt[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 120 | ▶ | my $fh = IO::File->new($log,$mode) or die "Cannot write to log file [$log]: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 120 | print $fh "$dt ", @_, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 120 | $fh->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 13 | q!Will code for a damn fine Balti!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||