| 1 | # ABSTRACT: Add a local distribution into the repository | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Pinto::Action::Add; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 37 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 37 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 37 | ▶ | use MooseX::Types::Moose qw(Bool ArrayRef Str); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 37 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 37 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 37 | ▶ | use Pinto::Util qw(sha256 current_author_id throw); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 37 | ▶ | use Pinto::Types qw(AuthorID FileList); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 37 | our $VERSION = '0.14'; # VERSION | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 37 | extends qw( Pinto::Action ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | has author => ( | ||||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||
| 26 | isa => AuthorID, | ||||||||||||||||||||||||||||
| 27 | 21 | ▶ | default => sub { $_[0]->pausecfg->{user} || current_author_id }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 37 | coerce => 1, | |||||||||||||||||||||||||||
| 29 | lazy => 1, | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 37 | has archives => ( | |||||||||||||||||||||||||||
| 33 | isa => FileList, | ||||||||||||||||||||||||||||
| 34 | traits => [qw(Array)], | ||||||||||||||||||||||||||||
| 35 | handles => { archives => 'elements' }, | ||||||||||||||||||||||||||||
| 36 | required => 1, | ||||||||||||||||||||||||||||
| 37 | coerce => 1, | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 37 | has no_fail => ( | |||||||||||||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||||||||||||
| 42 | isa => Bool, | ||||||||||||||||||||||||||||
| 43 | default => 0, | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | has no_index => ( | ||||||||||||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||||||||||||
| 48 | isa => ArrayRef [Str], | ||||||||||||||||||||||||||||
| 49 | 60 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 37 | ); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 37 | with qw( Pinto::Role::PauseConfig Pinto::Role::Committable Pinto::Role::Puller ); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 60 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 59 | 60 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 60 | my @missing = grep { not -e $_ } $self->archives; | |||||||||||||||||||||||||||
| 62 | 60 | $self->error("Archive $_ does not exist") for @missing; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 60 | ▶ | my @unreadable = grep { -e $_ and not -r $_ } $self->archives; | ||||||||||||||||||||||||||
|
Condition66%2/3
-e $_ && !(-r $_)
MC/DC0%0/2
-e $_ && !(-r $_)
-e $_
!(-r $_)
Truth table66%2/3
A && not(B)
A= -e $_B= !(-r $_)
| |||||||||||||||||||||||||||||
| 65 | 60 | $self->error("Archive $_ is not readable") for @unreadable; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 60 | ▶ | throw "Some archives are missing or unreadable" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@missing or @unreadable
MC/DC50%1/2
@missing or @unreadable
@missing
@unreadable
Truth table66%2/3
A or B
A= @missingB= @unreadable
| |||||||||||||||||||||||||||||
| 68 | if @missing or @unreadable; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 59 | return $self; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 59 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=2 SCAR=8.2
| |||||||||||||||||||||||||||||
| 76 | 59 | my ($self) = @_; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 59 | for my $archive ( $self->archives ) { | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 59 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 81 | 59 | $self->repo->svp_begin; | |||||||||||||||||||||||||||
| 82 | 59 | my $dist = $self->_add($archive); | |||||||||||||||||||||||||||
| 83 | 59 | ▶ | push @{$self->affected}, $dist if $dist; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | throw $_ unless $self->no_fail; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | $self->result->failed( because => $_ ); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | $self->repo->svp_rollback; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | $self->error("$_"); | |||||||||||||||||||||||||||
| 92 | 0 | $self->error("Archive $archive failed...continuing anyway"); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 59 | ▶ | finally { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 95 | 59 | my ($error) = @_; | |||||||||||||||||||||||||||
| 96 | 59 | ▶ | $self->repo->svp_release unless $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 59 | }; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 59 | $self->chrome->progress_done; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 59 | return $self; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 59 | ▶ | sub _add { | ||||||||||||||||||||||||||
|
Subroutine
_add: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 108 | 59 | my ( $self, $archive ) = @_; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 59 | my $dist; | |||||||||||||||||||||||||||
| 111 | 59 | ▶ | if ( my $dupe = $self->_check_for_duplicate($archive) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | $self->warning("$archive is the same as $dupe -- using $dupe instead"); | |||||||||||||||||||||||||||
| 113 | 0 | $dist = $dupe; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | else { | ||||||||||||||||||||||||||||
| 116 | 59 | $self->info("Adding $archive to the repository"); | |||||||||||||||||||||||||||
| 117 | 59 | $dist = $self->repo->add_distribution( archive => $archive, author => $self->author ); | |||||||||||||||||||||||||||
| 118 | 59 | $self->_apply_exclusions($dist); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 59 | $self->notice( "Registering $dist on stack " . $self->stack ); | |||||||||||||||||||||||||||
| 122 | 59 | ($dist, undef, undef) = $self->pull( target => $dist ); # Registers dist and pulls prereqs | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 59 | return $dist; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 59 | ▶ | sub _check_for_duplicate { | ||||||||||||||||||||||||||
|
Subroutine
_check_for_duplicate: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||
| 130 | 59 | my ( $self, $archive ) = @_; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 59 | my $sha256 = sha256($archive); | |||||||||||||||||||||||||||
| 133 | 59 | my $dupe = $self->repo->db->schema->search_distribution( { sha256 => $sha256 } )->first; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 59 | ▶ | return if not defined $dupe; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | return $dupe if $archive->basename eq $dupe->archive; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | throw "Archive $archive is the same as $dupe but with different name"; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 59 | ▶ | sub _apply_exclusions { | ||||||||||||||||||||||||||
|
Subroutine
_apply_exclusions: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 144 | 59 | my ( $self, $dist ) = @_; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 59 | ▶ | my @rules = map { s/^\/// ? qr/$_/ : $_ } @{ $self->no_index }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 2 | ▶ | my $matcher = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 149 | 2 | my ( $rule, $pkg ) = @_; | |||||||||||||||||||||||||||
| 150 | 2 | ▶ | return ref $rule eq 'Regexp' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | ? $pkg->name =~ $rule | ||||||||||||||||||||||||||||
| 152 | : $pkg->name eq $rule; | ||||||||||||||||||||||||||||
| 153 | 59 | }; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 59 | my @pkgs = $dist->packages; | |||||||||||||||||||||||||||
| 156 | 59 | for my $rule (@rules) { | |||||||||||||||||||||||||||
| 157 | 1 | for my $pkg (@pkgs) { | |||||||||||||||||||||||||||
| 158 | 2 | ▶ | next unless $matcher->( $rule, $pkg ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 1 | $self->warning("Excluding matching package $pkg from index"); | |||||||||||||||||||||||||||
| 160 | 1 | $pkg->delete; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 59 | ▶ | throw "Distribution $dist has no packages left" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | if $dist->packages->count == 0; | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 59 | return $self; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 37 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 175 | 37 | 1; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | __END__ | ||||||||||||||||||||||||||||