| 1 | # ABSTRACT: Coordinates the database, files, and indexes | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Pinto::Repository; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 57 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 57 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 57 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 57 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 57 | ▶ | use File::Find; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 57 | ▶ | use Path::Class; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 57 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 57 | ▶ | use Pinto::Store; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 57 | ▶ | use Pinto::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 57 | ▶ | use Pinto::Locker; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 57 | ▶ | use Pinto::Database; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 57 | ▶ | use Pinto::PackageExtractor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 57 | ▶ | use Pinto::Locator::Multiplex; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 57 | ▶ | use Pinto::PrerequisiteWalker; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 57 | ▶ | use Pinto::Util qw(itis debug mksymlink throw); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 57 | ▶ | use Pinto::Types qw(Dir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 57 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 57 | our $VERSION = '0.14'; # VERSION | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 57 | Readonly our $REPOSITORY_VERSION => 1; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 57 | with qw( Pinto::Role::UserAgent ); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 57 | has root => ( | |||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||
| 43 | isa => Dir, | ||||||||||||||||||||||||||||
| 44 | required => 1, | ||||||||||||||||||||||||||||
| 45 | coerce => 1, | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | has config => ( | ||||||||||||||||||||||||||||
| 50 | is => 'ro', | ||||||||||||||||||||||||||||
| 51 | isa => 'Pinto::Config', | ||||||||||||||||||||||||||||
| 52 | 289 | ▶ | default => sub { Pinto::Config->new( root => $_[0]->root ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 57 | lazy => 1, | |||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | has db => ( | ||||||||||||||||||||||||||||
| 58 | is => 'ro', | ||||||||||||||||||||||||||||
| 59 | isa => 'Pinto::Database', | ||||||||||||||||||||||||||||
| 60 | 203 | ▶ | default => sub { Pinto::Database->new( repo => $_[0] ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 57 | lazy => 1, | |||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | has store => ( | ||||||||||||||||||||||||||||
| 66 | is => 'ro', | ||||||||||||||||||||||||||||
| 67 | isa => 'Pinto::Store', | ||||||||||||||||||||||||||||
| 68 | 45 | ▶ | default => sub { Pinto::Store->new( repo => $_[0] ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 69 | 57 | lazy => 1, | |||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | has locator => ( | ||||||||||||||||||||||||||||
| 74 | is => 'ro', | ||||||||||||||||||||||||||||
| 75 | isa => 'Pinto::Locator', | ||||||||||||||||||||||||||||
| 76 | handles => [ qw(locate) ], | ||||||||||||||||||||||||||||
| 77 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | 1 | my $cache_dir = $self->config->cache_dir; | |||||||||||||||||||||||||||
| 80 | 1 | my $mux = Pinto::Locator::Multiplex->new(cache_dir => $cache_dir); | |||||||||||||||||||||||||||
| 81 | 1 | return $mux->assemble($self->config->sources_list) | |||||||||||||||||||||||||||
| 82 | }, | ||||||||||||||||||||||||||||
| 83 | 57 | lazy => 1, | |||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | has locker => ( | ||||||||||||||||||||||||||||
| 88 | is => 'ro', | ||||||||||||||||||||||||||||
| 89 | isa => 'Pinto::Locker', | ||||||||||||||||||||||||||||
| 90 | handles => [qw(lock unlock)], | ||||||||||||||||||||||||||||
| 91 | 130 | ▶ | default => sub { Pinto::Locker->new( repo => $_[0] ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 92 | 57 | lazy => 1, | |||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 178 | ▶ | sub get_stack { | ||||||||||||||||||||||||||
|
Subroutine
get_stack: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 178 | my ( $self, $stack ) = @_; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 178 | ▶ | my $got = $self->get_stack_maybe($stack) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | or throw "Stack $stack does not exist"; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 171 | return $got; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 295 | ▶ | sub get_stack_maybe { | ||||||||||||||||||||||||||
|
Subroutine
get_stack_maybe: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 295 | my ( $self, $stack ) = @_; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 295 | ▶ | return $stack if itis( $stack, 'Pinto::Schema::Result::Stack' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 295 | ▶ | return $self->get_default_stack if not $stack; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 229 | my $where = { name => $stack }; | |||||||||||||||||||||||||||
| 117 | 229 | return $self->db->schema->find_stack($where); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 66 | ▶ | sub get_default_stack { | ||||||||||||||||||||||||||
|
Subroutine
get_default_stack: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 66 | my ($self) = @_; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 66 | my $where = { is_default => 1 }; | |||||||||||||||||||||||||||
| 127 | 66 | my @stacks = $self->db->schema->search_stack($where)->all; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # Assert that there is no more than one default stack | ||||||||||||||||||||||||||||
| 130 | 66 | ▶ | throw "PANIC: There must be no more than one default stack" if @stacks > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # Error if the default stack has been set | ||||||||||||||||||||||||||||
| 133 | 66 | ▶ | throw "The default stack has not been set" if @stacks == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 61 | return $stacks[0]; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | ▶ | sub get_all_stacks { | ||||||||||||||||||||||||||
|
Subroutine
get_all_stacks: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 1 | return $self->db->schema->stack_rs->all; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub get_revision { | ||||||||||||||||||||||||||
|
Subroutine
get_revision: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 0 | my ($self, $revision) = @_; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | my $rev = $self->get_revision_maybe($revision) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | or throw "No such revision $revision exists"; | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | return $rev; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 9 | ▶ | sub get_revision_maybe { | ||||||||||||||||||||||||||
|
Subroutine
get_revision_maybe: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 9 | my ( $self, $revision ) = @_; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 9 | ▶ | return $revision if itis( $revision, 'Pinto::Schema::Result::Revision' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 9 | my $where = { uuid => { like => lc "$revision%" } }; | |||||||||||||||||||||||||||
| 168 | 9 | my @revs = $self->db->schema->search_revision($where); | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 9 | ▶ | if ( @revs > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | my $msg = "Revision ID $revision is ambiguous. Possible matches are:\n"; | |||||||||||||||||||||||||||
| 172 | 0 | $msg .= $_->to_string("%i: %{48}T\n") for @revs; | |||||||||||||||||||||||||||
| 173 | 0 | throw $msg; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 9 | ▶ | return @revs ? $revs[0] : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 5 | ▶ | sub get_package { | ||||||||||||||||||||||||||
|
Subroutine
get_package: called CC=9 SCAR=37.2
Pod
documented
| |||||||||||||||||||||||||||||
| 183 | 5 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 5 | my $target = $args{target}; | |||||||||||||||||||||||||||
| 186 | 5 | my $pkg_name = $args{name}; | |||||||||||||||||||||||||||
| 187 | 5 | my $dist_path = $args{path}; | |||||||||||||||||||||||||||
| 188 | 5 | my $schema = $self->db->schema; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # Retrieve latest version of package that satisfies the target | ||||||||||||||||||||||||||||
| 191 | 5 | ▶ | if ($target) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 192 | 5 | my $where = {name => $target->name}; | |||||||||||||||||||||||||||
| 193 | 5 | ▶ | return unless my @pkgs = $schema->search_package( $where )->with_distribution; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 0 | ▶ | return unless my $latest = first { $target->is_satisfied_by($_->version) } reverse sort { $a <=> $b } @pkgs; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 0 | return $latest; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | # Retrieve package from a specific distribution | ||||||||||||||||||||||||||||
| 199 | ▶ | elsif ( $pkg_name && $dist_path ) { | |||||||||||||||||||||||||||
|
Condition0%0/3
$pkg_name and $dist_path
MC/DC0%0/2
$pkg_name and $dist_path
$pkg_name
$dist_path
Truth table0%0/3
A and B
A= $pkg_nameB= $dist_path
| |||||||||||||||||||||||||||||
| 200 | 0 | my ( $author, $archive ) = Pinto::Util::parse_dist_path($dist_path); | |||||||||||||||||||||||||||
| 201 | 0 | my $where = {'me.name' => $pkg_name, 'distribution.author' => $author, 'distribution.archive' => $archive}; | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | return unless my @pkgs = $schema->search_package($where)->with_distribution; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | return $pkgs[0]; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | # Retrieve latest version of package in the entire repository | ||||||||||||||||||||||||||||
| 207 | elsif ($pkg_name) { | ||||||||||||||||||||||||||||
| 208 | 0 | my $where = { name => $pkg_name }; | |||||||||||||||||||||||||||
| 209 | 0 | ▶ | return unless my @pkgs = $schema->search_package($where)->with_distribution; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 0 | return (reverse sort { $a <=> $b } @pkgs)[0]; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | throw 'Invalid arguments'; | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 66 | ▶ | sub get_distribution { | ||||||||||||||||||||||||||
|
Subroutine
get_distribution: called CC=8 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||
| 220 | 66 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 66 | my $rs = $self->db->schema->distribution_rs->with_packages; | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | # Retrieve a distribution by target | ||||||||||||||||||||||||||||
| 225 | 66 | ▶ | if ( my $target = $args{target} ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 226 | 5 | ▶ | if ( itis( $target, 'Pinto::Target::Distribution' ) ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 227 | 0 | return $rs->find_by_author_archive( $target->author, $target->archive ); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | elsif ( itis( $target, 'Pinto::Target::Package' ) ) { | ||||||||||||||||||||||||||||
| 230 | 5 | ▶ | return unless my $pkg = $self->get_package( target => $target ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 0 | return $pkg->distribution; | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | throw 'Invalid arguments'; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | # Retrieve a distribution by its path (e.g. AUTHOR/Dist-1.0.tar.gz) | ||||||||||||||||||||||||||||
| 238 | elsif ( my $path = $args{path} ) { | ||||||||||||||||||||||||||||
| 239 | 1 | my ( $author, $archive ) = Pinto::Util::parse_dist_path($path); | |||||||||||||||||||||||||||
| 240 | 1 | return $rs->find_by_author_archive( $author, $archive ); | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | # Retrieve a distribution by author and archive | ||||||||||||||||||||||||||||
| 244 | elsif ( my $author = $args{author} ) { | ||||||||||||||||||||||||||||
| 245 | 60 | ▶ | my $archive = $args{archive} or throw "Must specify archive with author"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 60 | return $rs->find_by_author_archive( $author, $archive ); | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 0 | throw 'Invalid arguments'; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 5 | ▶ | sub ups_distribution { | ||||||||||||||||||||||||||
|
Subroutine
ups_distribution: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 256 | 5 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 5 | ▶ | return unless my $found = $self->locate( %args ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 0 | return $self->fetch_distribution( uri => $found->{uri} ); | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 59 | ▶ | sub add_distribution { | ||||||||||||||||||||||||||
|
Subroutine
add_distribution: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 266 | 59 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 59 | my $archive = $args{archive}; | |||||||||||||||||||||||||||
| 269 | 59 | my $author = uc $args{author}; | |||||||||||||||||||||||||||
| 270 | 59 | ▶ | my $source = $args{source} || 'LOCAL'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'source'} || 'LOCAL'
MC/DC0%0/1
$args{'source'} || 'LOCAL'
$args{'source'}
Truth table50%1/2
A
A= $args{'source'}
| |||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 59 | $self->assert_archive_not_duplicate( $author, $archive ); | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | # Assemble the basic structure... | ||||||||||||||||||||||||||||
| 275 | 59 | my $dist_struct = { | |||||||||||||||||||||||||||
| 276 | author => $author, | ||||||||||||||||||||||||||||
| 277 | source => $source, | ||||||||||||||||||||||||||||
| 278 | archive => $archive->basename, | ||||||||||||||||||||||||||||
| 279 | mtime => Pinto::Util::mtime($archive), | ||||||||||||||||||||||||||||
| 280 | md5 => Pinto::Util::md5($archive), | ||||||||||||||||||||||||||||
| 281 | sha256 => Pinto::Util::sha256($archive) | ||||||||||||||||||||||||||||
| 282 | }; | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 59 | my $extractor = Pinto::PackageExtractor->new( archive => $archive ); | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | # Add provided packages... | ||||||||||||||||||||||||||||
| 287 | 59 | my @provides = $extractor->provides; | |||||||||||||||||||||||||||
| 288 | 59 | $dist_struct->{packages} = \@provides; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | # Add required packages... | ||||||||||||||||||||||||||||
| 291 | 59 | my @requires = $extractor->requires; | |||||||||||||||||||||||||||
| 292 | 59 | $dist_struct->{prerequisites} = \@requires; | |||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | # Add metadata... | ||||||||||||||||||||||||||||
| 295 | 59 | my $metadata = $extractor->metadata; | |||||||||||||||||||||||||||
| 296 | 59 | $dist_struct->{metadata} = $metadata; | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 59 | my $p = scalar @provides; | |||||||||||||||||||||||||||
| 299 | 59 | my $r = scalar @requires; | |||||||||||||||||||||||||||
| 300 | 59 | debug "Distribution $archive provides $p and requires $r packages"; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | # Update database *before* moving the archive into the | ||||||||||||||||||||||||||||
| 303 | # repository, so if there is an error in the DB, we can stop and | ||||||||||||||||||||||||||||
| 304 | # the repository will still be clean. | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 59 | my $dist = $self->db->schema->create_distribution($dist_struct); | |||||||||||||||||||||||||||
| 307 | 59 | $self->store->add_archive( $archive => $dist->native_path ); | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 59 | return $dist; | |||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 0 | ▶ | sub fetch_distribution { | ||||||||||||||||||||||||||
|
Subroutine
fetch_distribution: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 316 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 0 | my $uri = $args{uri}; | |||||||||||||||||||||||||||
| 319 | 0 | my $path = $uri->path; | |||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 0 | my $existing = $self->get_distribution( path => $path ); | |||||||||||||||||||||||||||
| 322 | 0 | ▶ | throw "Distribution $existing already exists" if $existing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | my ( $author, undef ) = Pinto::Util::parse_dist_path($path); | |||||||||||||||||||||||||||
| 325 | 0 | my $archive = $self->mirror_temporary( $uri ); | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | my $dist = $self->add_distribution( | |||||||||||||||||||||||||||
| 328 | archive => $archive, | ||||||||||||||||||||||||||||
| 329 | author => $author, | ||||||||||||||||||||||||||||
| 330 | source => $uri, | ||||||||||||||||||||||||||||
| 331 | ); | ||||||||||||||||||||||||||||
| 332 | 0 | return $dist; | |||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 0 | ▶ | sub delete_distribution { | ||||||||||||||||||||||||||
|
Subroutine
delete_distribution: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 338 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 0 | my $dist = $args{dist}; | |||||||||||||||||||||||||||
| 341 | 0 | my $force = $args{force}; | |||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 0 | for my $reg ( $dist->registrations ) { | |||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | # TODO: say which stack it is pinned to | ||||||||||||||||||||||||||||
| 346 | 0 | ▶ | throw "$dist is pinned to a stack and cannot be deleted" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$reg->is_pinned and not $force
MC/DC0%0/2
$reg->is_pinned and not $force
$reg->is_pinned
not $force
Truth table0%0/3
A and not(B)
A= $reg->is_pinnedB= not $force
| |||||||||||||||||||||||||||||
| 347 | if $reg->is_pinned and not $force; | ||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 0 | $dist->delete; | |||||||||||||||||||||||||||
| 351 | 0 | my $basedir = $self->config->authors_id_dir; | |||||||||||||||||||||||||||
| 352 | 0 | $self->store->remove_archive( $dist->native_path($basedir) ); | |||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | return $self; | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 1 | ▶ | sub package_count { | ||||||||||||||||||||||||||
|
Subroutine
package_count: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 360 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 1 | return $self->db->schema->package_rs->count; | |||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 1 | ▶ | sub distribution_count { | ||||||||||||||||||||||||||
|
Subroutine
distribution_count: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 368 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 1 | return $self->db->schema->distribution_rs->count; | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 0 | ▶ | sub stack_count { | ||||||||||||||||||||||||||
|
Subroutine
stack_count: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 376 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 0 | return $self->db->schema->stack_rs->count; | |||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 0 | ▶ | sub revision_count { | ||||||||||||||||||||||||||
|
Subroutine
revision_count: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 384 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 0 | return $self->db->schema->revision_rs->count; | |||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 173 | ▶ | sub txn_begin { | ||||||||||||||||||||||||||
|
Subroutine
txn_begin: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 392 | 173 | my ($self) = @_; | |||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 173 | debug 'Beginning db transaction'; | |||||||||||||||||||||||||||
| 395 | 173 | $self->db->schema->txn_begin; | |||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 173 | return $self; | |||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 72 | ▶ | sub txn_rollback { | ||||||||||||||||||||||||||
|
Subroutine
txn_rollback: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 403 | 72 | my ($self) = @_; | |||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 72 | debug 'Rolling back db transaction'; | |||||||||||||||||||||||||||
| 406 | 72 | $self->db->schema->txn_rollback; | |||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 72 | return $self; | |||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 101 | ▶ | sub txn_commit { | ||||||||||||||||||||||||||
|
Subroutine
txn_commit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 414 | 101 | my ($self) = @_; | |||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 101 | debug 'Committing db transaction'; | |||||||||||||||||||||||||||
| 417 | 101 | $self->db->schema->txn_commit; | |||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 101 | return $self; | |||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 62 | ▶ | sub svp_begin { | ||||||||||||||||||||||||||
|
Subroutine
svp_begin: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 425 | 62 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | 62 | debug 'Beginning db savepoint'; | |||||||||||||||||||||||||||
| 428 | 62 | $self->db->schema->svp_begin($name); | |||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 62 | return $self; | |||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 0 | ▶ | sub svp_rollback { | ||||||||||||||||||||||||||
|
Subroutine
svp_rollback: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 436 | 0 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 0 | debug 'Rolling back db savepoint'; | |||||||||||||||||||||||||||
| 439 | 0 | $self->db->schema->svp_rollback($name); | |||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 0 | return $self; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | 59 | ▶ | sub svp_release { | ||||||||||||||||||||||||||
|
Subroutine
svp_release: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 447 | 59 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | 59 | debug 'Releasing db savepoint'; | |||||||||||||||||||||||||||
| 450 | 59 | $self->db->schema->svp_release($name); | |||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | 59 | return $self; | |||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 85 | ▶ | sub create_stack { | ||||||||||||||||||||||||||
|
Subroutine
create_stack: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 459 | 85 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 85 | my $stk_name = $args{name}; | |||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 85 | ▶ | throw "Stack $stk_name already exists" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 464 | if $self->get_stack_maybe( $stk_name ); | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 85 | my $root = $self->db->get_root_revision; | |||||||||||||||||||||||||||
| 467 | 85 | my $stack = $self->db->schema->create_stack( { %args, head => $root } ); | |||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | 85 | $stack->make_filesystem; | |||||||||||||||||||||||||||
| 470 | 85 | $stack->write_index; | |||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 85 | return $stack; | |||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | 8 | ▶ | sub copy_stack { | ||||||||||||||||||||||||||
|
Subroutine
copy_stack: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 478 | 8 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | 8 | my $copy_name = $args{name}; | |||||||||||||||||||||||||||
| 481 | 8 | my $stack = delete $args{stack}; | |||||||||||||||||||||||||||
| 482 | 8 | my $orig_name = $stack->name; | |||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | 8 | ▶ | if ( my $existing = $self->get_stack_maybe( $copy_name ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 485 | 2 | throw "Stack $existing already exists"; | |||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | 6 | my $dupe = $stack->duplicate(%args); | |||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 6 | $dupe->make_filesystem; | |||||||||||||||||||||||||||
| 491 | 6 | $dupe->write_index; | |||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | 6 | return $dupe; | |||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 4 | ▶ | sub rename_stack { | ||||||||||||||||||||||||||
|
Subroutine
rename_stack: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 499 | 4 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | 4 | my $new_name = $args{to}; | |||||||||||||||||||||||||||
| 502 | 4 | my $stack = delete $args{stack}; | |||||||||||||||||||||||||||
| 503 | 4 | my $old_name = $stack->name; | |||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 4 | ▶ | if (my $existing_stack = $self->get_stack_maybe( $new_name )) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 506 | 3 | my $is_different_stack = lc $new_name ne lc $existing_stack->name; | |||||||||||||||||||||||||||
| 507 | 3 | ▶ | throw "Stack $new_name already exists" if $is_different_stack || $new_name eq $old_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$is_different_stack or $new_name eq $old_name
MC/DC50%1/2
$is_different_stack or $new_name eq $old_name
$is_different_stack
$new_name eq $old_name
Truth table66%2/3
A or B
A= $is_different_stackB= $new_name eq $old_name
| |||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | 3 | $stack->rename_filesystem( to => $new_name ); | |||||||||||||||||||||||||||
| 511 | 2 | $stack->rename( to => $new_name ); | |||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 2 | return $stack; | |||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | 4 | ▶ | sub kill_stack { | ||||||||||||||||||||||||||
|
Subroutine
kill_stack: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 519 | 4 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | 4 | my $stack = $args{stack}; | |||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | 4 | $stack->kill; | |||||||||||||||||||||||||||
| 524 | 2 | $stack->kill_filesystem; | |||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 2 | return $stack; | |||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | 73 | ▶ | sub link_modules_dir { | ||||||||||||||||||||||||||
|
Subroutine
link_modules_dir: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 532 | 73 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | 73 | my $target_dir = $args{to}; | |||||||||||||||||||||||||||
| 535 | 73 | my $modules_dir = $self->config->modules_dir; | |||||||||||||||||||||||||||
| 536 | 73 | my $root_dir = $self->config->root_dir; | |||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | 73 | ▶ | if ( -e $modules_dir or -l $modules_dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-e $modules_dir or -l $modules_dir
MC/DC100%2/2
-e $modules_dir or -l $modules_dir
-e $modules_dir
-l $modules_dir
Truth table100%3/3
A or B
A= -e $modules_dirB= -l $modules_dir
| |||||||||||||||||||||||||||||
| 539 | 5 | debug "Unlinking $modules_dir"; | |||||||||||||||||||||||||||
| 540 | 5 | ▶ | unlink $modules_dir or throw $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | 73 | debug "Linking $modules_dir to $target_dir"; | |||||||||||||||||||||||||||
| 544 | 73 | mksymlink( $modules_dir => $target_dir->relative($root_dir) ); | |||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | 73 | return $self; | |||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | 2 | ▶ | sub unlink_modules_dir { | ||||||||||||||||||||||||||
|
Subroutine
unlink_modules_dir: called CC=4 SCAR=15.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 552 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | 2 | my $modules_dir = $self->config->modules_dir; | |||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | 2 | ▶ | if ( -e $modules_dir or -l $modules_dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $modules_dir or -l $modules_dir
MC/DC0%0/2
-e $modules_dir or -l $modules_dir
-e $modules_dir
-l $modules_dir
Truth table33%1/3
A or B
A= -e $modules_dirB= -l $modules_dir
| |||||||||||||||||||||||||||||
| 557 | 2 | debug "Unlinking $modules_dir"; | |||||||||||||||||||||||||||
| 558 | 2 | ▶ | unlink $modules_dir or throw $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 2 | return $self; | |||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | 64 | ▶ | sub clean_files { | ||||||||||||||||||||||||||
|
Subroutine
clean_files: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 568 | 64 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | 64 | my $deleted = 0; | |||||||||||||||||||||||||||
| 571 | 64 | my $dists_rs = $self->db->schema->distribution_rs->search( undef, { prefetch => {} } ); | |||||||||||||||||||||||||||
| 572 | 0 | my %known_dists = map { ( $_->to_string => 1 ) } $dists_rs->all; | |||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | 470 | ▶ | my $callback = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||
| 575 | 470 | ▶ | return if not -f $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | 121 | my $path = Path::Class::file($_); | |||||||||||||||||||||||||||
| 578 | 121 | my $author = $path->parent->basename; | |||||||||||||||||||||||||||
| 579 | 121 | my $archive = $path->basename; | |||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | 121 | ▶ | return if $archive eq 'CHECKSUMS'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 582 | 121 | ▶ | return if $archive eq '01mailrc.txt.gz'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 583 | 57 | ▶ | return if exists $known_dists{"$author/$archive"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | 57 | debug "Removing orphaned archive at $path"; | |||||||||||||||||||||||||||
| 586 | 57 | $self->store->remove_archive($path); | |||||||||||||||||||||||||||
| 587 | 57 | $deleted++; | |||||||||||||||||||||||||||
| 588 | 64 | }; | |||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | 64 | my $authors_dir = $self->config->authors_dir; | |||||||||||||||||||||||||||
| 591 | 64 | debug "Cleaning orphaned archives beneath $authors_dir"; | |||||||||||||||||||||||||||
| 592 | 64 | File::Find::find( { no_chdir => 1, wanted => $callback }, $authors_dir ); | |||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | 64 | return $deleted; | |||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | 0 | ▶ | sub optimize_database { | ||||||||||||||||||||||||||
|
Subroutine
optimize_database: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 600 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||
| 602 | 0 | debug 'Removing empty database pages'; | |||||||||||||||||||||||||||
| 603 | 0 | $self->db->schema->storage->dbh->do('VACUUM;'); | |||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | 0 | debug 'Updating database statistics'; | |||||||||||||||||||||||||||
| 606 | 0 | $self->db->schema->storage->dbh->do('ANALYZE;'); | |||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | 0 | return $self; | |||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | 206 | ▶ | sub get_version { | ||||||||||||||||||||||||||
|
Subroutine
get_version: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 615 | 206 | my ($self) = @_; | |||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||
| 617 | 206 | my $version_file = $self->config->version_file; | |||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | 206 | ▶ | return undef if not -e $version_file; # Old repos have no version file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||
| 621 | 206 | my $version = $version_file->slurp( chomp => 1 ); | |||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||
| 623 | 206 | return $version; | |||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | 70 | ▶ | sub set_version { | ||||||||||||||||||||||||||
|
Subroutine
set_version: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 629 | 70 | my ( $self, $version ) = @_; | |||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||
| 631 | 70 | ▶ | $version ||= $REPOSITORY_VERSION; | ||||||||||||||||||||||||||
|
Condition33%1/3
$version ||= $Pinto::Repository::REPOSITORY_VERSION
MC/DC0%0/2
$version ||= $Pinto::Repository::REPOSITORY_VERSION
$version
$Pinto::Repository::REPOSITORY_VERSION
Truth table33%1/3
A ||= B
A= $versionB= $Pinto::Repository::REPOSITORY_VERSION
| |||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||
| 633 | 70 | my $version_fh = $self->config->version_file->openw; | |||||||||||||||||||||||||||
| 634 | 70 | print {$version_fh} $version, "\n"; | |||||||||||||||||||||||||||
| 635 | 70 | close $version_fh; | |||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||
| 637 | 70 | return $self; | |||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||
| 640 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||
| 642 | 59 | ▶ | sub assert_archive_not_duplicate { | ||||||||||||||||||||||||||
|
Subroutine
assert_archive_not_duplicate: called CC=5 SCAR=17.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 643 | 59 | my ( $self, $author, $archive ) = @_; | |||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||
| 645 | 59 | ▶ | throw "Archive $archive does not exist" if not -e $archive; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 646 | 59 | ▶ | throw "Archive $archive is not readable" if not -r $archive; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | 59 | my $basename = $archive->basename; | |||||||||||||||||||||||||||
| 649 | 59 | ▶ | if ( my $same_path = $self->get_distribution( author => $author, archive => $basename ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 650 | 0 | throw "A distribution already exists as $same_path"; | |||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | 59 | my $sha256 = Pinto::Util::sha256($archive); | |||||||||||||||||||||||||||
| 654 | 59 | my $dupe = $self->db->schema->search_distribution( { sha256 => $sha256 } )->first; | |||||||||||||||||||||||||||
| 655 | 59 | ▶ | throw "Archive $archive is identical to $dupe" if $dupe; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | 59 | return $self; | |||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||
| 660 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||
| 662 | 205 | ▶ | sub assert_version_ok { | ||||||||||||||||||||||||||
|
Subroutine
assert_version_ok: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 663 | 205 | my ($self) = @_; | |||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | 205 | my $repo_version = $self->get_version; | |||||||||||||||||||||||||||
| 666 | 205 | my $code_version = $REPOSITORY_VERSION; | |||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||
| 668 | 57 | ▶ | no warnings qw(uninitialized); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 669 | 205 | ▶ | if ( $repo_version != $code_version ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 670 | 0 | my $msg = "Repository version ($repo_version) and Pinto version ($code_version) do not match.\n"; | |||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||
| 672 | # For really old repositories, the version is undefined and there is no automated | ||||||||||||||||||||||||||||
| 673 | # migration process. If the version is defined, then automatic migration should work. | ||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | 0 | ▶ | $msg .= | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 676 | defined $repo_version | ||||||||||||||||||||||||||||
| 677 | ? "Use the 'migrate' command to bring the repo up to date" | ||||||||||||||||||||||||||||
| 678 | : "Contact thaljef\@cpan.org for migration instructions"; | ||||||||||||||||||||||||||||
| 679 | 0 | throw $msg; | |||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||
| 682 | 205 | return $self; | |||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | 218 | ▶ | sub assert_sanity_ok { | ||||||||||||||||||||||||||
|
Subroutine
assert_sanity_ok: called CC=7 SCAR=21.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 688 | 218 | my ($self) = @_; | |||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||
| 690 | 218 | my $root_dir = $self->config->root_dir; | |||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||
| 692 | 218 | ▶ | throw "Directory $root_dir does not exist" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 693 | unless -e $root_dir; | ||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||
| 695 | 218 | ▶ | throw "$root_dir is not a directory" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 696 | unless -d $root_dir; | ||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | 218 | ▶ | throw "Directory $root_dir is not readable by you" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 699 | unless -r $root_dir; | ||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||
| 701 | 218 | ▶ | throw "Directory $root_dir is not writable by you" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 702 | unless -w $root_dir; | ||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||
| 704 | 218 | ▶ | throw "Directory $root_dir does not look like a Pinto repository" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $self->config->db_file and -e $self->config->authors_dir
MC/DC0%0/2
-e $self->config->db_file and -e $self->config->authors_dir
-e $self->config->db_file
-e $self->config->authors_dir
Truth table33%1/3
A and B
A= -e $self->config->db_fileB= -e $self->config->authors_dir
| |||||||||||||||||||||||||||||
| 705 | unless -e $self->config->db_file && -e $self->config->authors_dir; | ||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||
| 707 | 218 | return $self; | |||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||
| 710 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||
| 712 | 0 | ▶ | sub clear_cache { | ||||||||||||||||||||||||||
|
Subroutine
clear_cache: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 713 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||
| 715 | 0 | $self->locator->refresh; # Clears cache file from disk | |||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | 0 | return $self; | |||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||
| 720 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||
| 722 | 57 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||
| 724 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||
| 726 | 57 | 1; | |||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | __END__ | ||||||||||||||||||||||||||||