| 1 | # ABSTRACT: Storage for distribution archives | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Pinto::Store; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 58 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 58 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 58 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 58 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 58 | ▶ | use CPAN::Checksums; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 58 | ▶ | use Pinto::Util qw(debug throw); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 58 | our $VERSION = '0.14'; # VERSION | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 58 | with qw( Pinto::Role::UserAgent ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 58 | has repo => ( | |||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||
| 26 | isa => 'Pinto::Repository', | ||||||||||||||||||||||||||||
| 27 | weak_ref => 1, | ||||||||||||||||||||||||||||
| 28 | required => 1, | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 32 | # TODO: Use named arguments here... | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 59 | ▶ | sub add_archive { | ||||||||||||||||||||||||||
|
Subroutine
add_archive: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 59 | my ( $self, $origin, $destination ) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 59 | ▶ | throw "$origin does not exist" if not -e $origin; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 59 | ▶ | throw "$origin is not a file" if not -f $origin; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 59 | $self->mirror( $origin => $destination ); | |||||||||||||||||||||||||||
| 41 | 59 | $self->update_checksums( directory => $destination->parent ); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 59 | return $self; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 48 | # TODO: Use named arguments here... | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 57 | ▶ | sub remove_archive { | ||||||||||||||||||||||||||
|
Subroutine
remove_archive: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 57 | my ( $self, $archive_file ) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 57 | $self->remove_path( path => $archive_file ); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 57 | $self->update_checksums( directory => $archive_file->parent ); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 57 | return $self; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 114 | ▶ | sub remove_path { | ||||||||||||||||||||||||||
|
Subroutine
remove_path: called CC=7 SCAR=20.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 114 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 114 | my $path = $args{path}; | |||||||||||||||||||||||||||
| 66 | 114 | ▶ | throw "Must specify a path" if not $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 114 | ▶ | return if not -e $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 114 | ▶ | $path->remove or throw "Failed to remove path $path: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 114 | ▶ | while ( my $dir = $path->parent ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 342 | ▶ | last if $dir->children; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 228 | debug("Removing empty directory $dir"); | |||||||||||||||||||||||||||
| 75 | 228 | ▶ | $dir->remove or throw "Failed to remove directory $dir: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 228 | $path = $dir; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 114 | return $self; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 116 | ▶ | sub update_checksums { | ||||||||||||||||||||||||||
|
Subroutine
update_checksums: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 116 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 86 | 116 | my $dir = $args{directory}; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 116 | ▶ | return 0 if $ENV{PINTO_NO_CHECKSUMS}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 116 | ▶ | return 0 if not -e $dir; # Would be fishy! | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 116 | my @children = $dir->children; | |||||||||||||||||||||||||||
| 92 | 116 | ▶ | return if not @children; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 116 | my $cs_file = $dir->file('CHECKSUMS'); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 116 | ▶ | if ( -e $cs_file && @children == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-e $cs_file and @children == 1
MC/DC100%2/2
-e $cs_file and @children == 1
-e $cs_file
@children == 1
Truth table100%3/3
A and B
A= -e $cs_fileB= @children == 1
| |||||||||||||||||||||||||||||
| 97 | 57 | $self->remove_path( path => $cs_file ); | |||||||||||||||||||||||||||
| 98 | 57 | return 0; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 59 | debug("Generating $cs_file"); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | try { CPAN::Checksums::updatedir($dir) } catch { throw "CHECKSUM generation failed for $dir: $_" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.4
Subroutine
__ANON__: not called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 59 | return $self; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 58 | 1; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||