| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Verby::Action::Untar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | with qw/Verby::Action::Run/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = "0.04"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Archive::Tar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use File::stat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | sub do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do: called CC=1 SCAR=0.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | my $tarball = $c->tarball; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | my $dest = $c->dest; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | $c->logger->info("untarring '$tarball' into '$dest'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | $self->create_poe_session( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | c => $c, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | program => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | chdir $dest; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $self->tar_archive($c)->extract | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | or $c->logger->log_and_die("Archive::Tar->extract did not return a true value"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | program_debug_string => "Archive::Tar child", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | sub finished { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finished: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | $c->logger->info("finished untarring"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | $self->confirm($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | sub verify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify: called CC=9 SCAR=22.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | my $dest = $c->dest; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | my $main_dir; # the main directory in the archive, if any | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | my $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | my $tarball = $self->tar_archive( $c ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | foreach my $spec ( $tarball->list_files([qw/name size mtime/]) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | my ( $name, $size, $mtime ) = @{ $spec }{qw/name size mtime/}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # determine the top level unpack directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | my $top_dir = (File::Spec->splitdir($name))[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 5 | ▶ | if ( defined $main_dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | if ( $top_dir ne $main_dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $c->logger->warn("Archive has no main directory"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $main_dir = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | $main_dir = $top_dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | my $destfile = File::Spec->catfile($dest, $name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | my $existing = stat($destfile); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 5 | ▶ | unless ( $existing and ( -d $destfile or $existing->size == $size && $existing->mtime == $mtime ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$existing and -d $destfile || $existing->size == $size && $existing->mtime == $mtime
-d $destfile or $existing->size == $size and $existing->mtime == $mtime
$existing->size == $size and $existing->mtime == $mtime
MC/DC25%1/4
$existing and -d $destfile || $existing->size == $size && $existing->mtime == $mtime
$existing
-d $destfile
$existing->size == $size
$existing->mtime == $mtime
Truth table60%3/5
A and B or C and D
A= $existingB= -d $destfileC= $existing->size == $sizeD= $existing->mtime == $mtime
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | $c->logger->warn("file '$name' requires re-extraction") if $i; # it's ok only for the first file to be missing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | $c->main_dir(File::Spec->catdir($dest, $main_dir)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | ▶ | sub tar_archive { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tar_archive: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | ▶ | $c->archive_object || $c->archive_object(Archive::Tar::LogError->new($c->tarball)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | package Archive::Tar::LogError; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | use base qw(Archive::Tar); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | use Log::Dispatch::Config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub _error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | Log::Dispatch::Config->instance->log_and_die( level => "error", message => $_[1] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | __PACKAGE__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||